home *** CD-ROM | disk | FTP | other *** search
Wrap
/* File: DragText.cpp Contains: DragText class definition. Owned by: Craig Carper Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved. Change History (most recent first): <6> 12/17/96 CC 1612520: Call SetDroppable in InitPart and InitPartFromStorage. <5> 7/16/96 EL 1295068: Do not externalize unless dirty, Do not remove hfs info unless dirty. <4> 6/20/96 JP 1323103: made some logging optional <3> 5/24/96 jpa 1246074: SOM_CATCH --> SOM_TRY & CATCH --> CATCH_ALL To Do: • Restore allocation of ODCPlusSemanticInterface and add SIHelper object • AdjustMenus() is being called when the part is in an inactive window; is this right? Our fHasFocus flag then seems to be true (not investigated). • $$$$$ fDocument->frameIsActive is redundant with fHasFoci and fNeedsFoci. I suspect fDocument was introduced to support multiple display frames; perhaps it makes more sense to move fHasFoci and fNeedsFoci there, and to write fDocument as part info in the display frame. In Progress: */ #ifndef _ALTPOINT_ #include "AltPoint.h" // Use C++ savvy ODPoint and ODRect #endif #define SOM_Module_dragtext_Source #define VARIABLE_MACROS #include <DragText.xih> #ifndef _DRAGDEF_ #include <DragDef.h> #endif #ifndef _DRAGCONS_ #include <DragCons.h> #endif #ifndef _DRAGTXPV_ #include <DragTxPv.h> #endif #ifndef _PLFMDEF_ #include "PlfmDef.h" #endif #ifndef _SIHELPER_ #include "SIHelper.h" #endif #ifndef __QUICKDRAW__ #include <Quickdraw.h> #endif #ifndef __SCRIPT__ #include <Script.h> #endif #ifndef __STRING__ #include <String.h> #endif #ifndef __OSUTILS__ #include <OSUtils.h> // SysBeep, GetDateTime, etc. #endif #ifndef __OSEVENTS__ #include <OSEvents.h> #endif #ifndef __TOOLUTILS__ #include <ToolUtils.h> // HiWord etc. #endif #ifndef __SCRAP__ #include <Scrap.h> #endif #ifndef __LOWMEM__ #include <LowMem.h> #endif #ifndef __FILES__ #include <Files.h> #endif #ifdef __SC__ #ifndef __LANGUAGE__ #include <Language.h> #endif #endif // __SC__ #ifndef SOM_Module_OpenDoc_StdProps_defined #include <StdProps.xh> #endif #ifndef SOM_Module_OpenDoc_StdTypes_defined #include <StdTypes.xh> #endif #ifndef SOM_ODStorageUnit_xh #include <StorageU.xh> #endif #ifndef SOM_ODDraft_xh #include <Draft.xh> #endif #ifndef SOM_ODDocument_xh #include <Document.xh> #endif #ifndef SOM_ODContainer_xh #include <ODCtr.xh> #endif #ifndef SOM_ODSession_xh #include <ODSessn.xh> #endif #ifndef SOM_ODWindowState_xh #include <WinStat.xh> #endif #ifndef SOM_ODArbitrator_xh #include <Arbitrat.xh> #endif #ifndef SOM_ODDispatcher_xh #include <Disptch.xh> #endif #ifndef SOM_ODFrame_xh #include <Frame.xh> #endif #ifndef SOM_ODFacet_xh #include <Facet.xh> #endif #ifndef SOM_ODFrameFacetIterator_xh #include <FrFaItr.xh> #endif #ifndef SOM_ODCanvas_xh #include <Canvas.xh> #endif #ifndef SOM_ODDraft_xh #include <Draft.xh> #endif #ifndef SOM_ODShape_xh #include <Shape.xh> #endif #ifndef SOM_ODTransform_xh #include <Trnsform.xh> #endif #ifndef SOM_ODWindow_xh #include <Window.xh> #endif #ifndef SOM_ODMenuBar_xh #include <MenuBar.xh> #endif #ifndef _EXCEPT_ #include "Except.h" #endif #ifndef SOM_ODDragAndDrop_xh #include <DragDrp.xh> #endif #ifndef SOM_ODDragItemIterator_xh #include <DgItmIt.xh> #endif #ifndef SOM_ODTranslation_xh #include <Translt.xh> #endif #ifndef SOM_ODStorageUnitView_xh #include <SUView.xh> #endif #ifndef SOM_Module_OpenDoc_Commands_defined #include <CmdDefs.xh> #endif #ifndef SOM_ODUndo_xh #include <Undo.xh> #endif #ifndef SOM_ODFocusSet_xh #include <FocusSet.xh> #endif #ifndef SOM_Module_OpenDoc_Foci_defined #include <Foci.xh> #endif #ifndef _ODUTILS_ #include <ODUtils.h> #endif #ifndef _INFOUTIL_ #include <InfoUtil.h> #endif #ifndef _DOCUTILS_ #include <DocUtils.h> #endif #ifndef _USERSRCM_ #include "UseRsrcM.h" #endif #ifndef _ORDCOLL_ #include "OrdColl.h" #endif #ifndef SOM_ODClipboard_xh #include <Clipbd.xh> #endif #ifndef SOM_ODLink_xh #include <Link.xh> #endif #ifndef SOM_ODLinkSource_xh #include <LinkSrc.xh> #endif #ifndef SOM_ODLinkSpec_xh #include <LinkSpec.xh> #endif #ifndef _ODMEMORY_ #include "ODMemory.h" #endif #ifndef _ISOSTR_ #include "ISOStr.h" #endif #ifndef SOM_ODNameSpaceManager_xh #include <NmSpcMg.xh> #endif #ifndef SOM_ODValueNameSpace_xh #include <ValueNS.xh> #endif #ifndef SOM_Module_OpenDoc_StdDefs_defined #include <StdDefs.xh> //jpa #endif #ifndef _FOCUSLIB_ #include "FocusLib.h" // for drawing/printing #endif #ifndef __GXMATH__ #include <GXMath.h> #endif #ifndef __QDOFFSCREEN__ #include "QDOffscreen.h" // for GWorldPtr, StScrpHandle #endif #ifndef __STDLIB__ #include "stdlib.h" // for labs #endif #ifndef _PASCLSTR_ #include "PasclStr.h" #endif #ifndef _ITEXT_ #include <IText.h> #endif #ifndef __PROCESSES__ #include <Processes.h> #endif #ifndef __DIALOGS__ #include "Dialogs.h" #endif #ifndef _BARRAY_ #include <BArray.h> #endif #ifndef _STORUTIL_ #include <StorUtil.h> #endif #ifndef SOM_ODObjectNameSpace_xh #include "ObjectNS.xh" #endif #ifndef _WINUTILS_ #include "WinUtils.h" #endif #ifndef _ODDEBUG_ #include <ODDebug.h> #endif #ifndef SOM_ODFocusSetIterator_xh #include <FocusItr.xh> #endif #ifndef _TEMPOBJ_ #include <TempObj.h> #endif #ifndef _TEMPITER_ #include <TempIter.h> #endif #ifndef SOM_AppleTestDrag_SemtIntf_xh #include <DragSI.xh> #endif #ifndef SOM_Module_OpenDoc_StandardExtensions_defined #include <StdExts.xh> #endif #pragma segment DragText //============================================================================== // Constants //============================================================================== #define DRAGTEXT_SUPPORTS_SCRIPTING 1 #define ODDebugCursor 0 // debug cursor location in MouseEnter etc. // Define this symbol to enable support of kODKindTestDrag and allow linking #define SUPPORT_TESTDRAG_KIND #define SHOW_LINK_BORDERS #undef DEBUG_LINK_BORDERS // Allow links to testdrag and styled text content #undef LINK_TO_TEXT_ONLY // Define to test transmission of content frame property to link destination #undef BOGUS_CONTENT_FRAME #undef SHOW_SCROLL_BARS #undef SHOW_TEXT_MENU #define SHOW_CLIPBOARD_PASTE_AS_DIALOG #define SHOW_DROP_PASTE_AS_DIALOG #define SSREMOVEWORKAROUND // The following #define is used for trying out promise resolution. // It creates a storage unit during promise resolution. This would cause // CMDraft to throw if CMDraft is not implemented correctly. #undef TRYOUT_PROMISE // The following #define is used to test creating a TEXT file by dragging // to the Finder. #undef TRYOUT_PROMISE_FILE #define MaxDocumentCount 8 #define kDTIdleFrequency 16 #define InitialH 16 #define InitialV 42 const char kRightArrow = 0x1D; const char kLeftArrow = 0x1C; const char kUpArrow = 0x1E; const char kDownArrow = 0x1F; //============================================================================== // Local Structs //============================================================================== struct UndoInfo { ODFrame* displayFrame; ODCommandID command; ODULong start; ODULong end; ODPtr text; ODHandle style; }; //============================================================================== // DragText Command Numbers //============================================================================== #define cDTSampleOne 24001 #define cDTSampleTwo 24002 #define cDTTyping 29999 #define cDTStyling 29998 #define kUndoIt 1 #define kRedoIt 2 //============================================================================== // Local function declarations //============================================================================== static void ShowAlert(Environment *ev, ODSShort alertID, ODFrame* frame); static void ShowErrorAlert(Environment *ev, Str255 message, ODError error, ODFrame* frame); static void ShowInfoAlert(Environment *ev, Str255 message, ODFrame* frame); //============================================================================== // Local functions //============================================================================== static void SetTextFont(TEHandle theTE, ODSShort fontNum) { TextStyle *newStyle = (TextStyle *) ODNewPtr(sizeof(TextStyle), kDefaultHeapID); (*newStyle).tsFont = fontNum; TESetStyle(doFont, newStyle, kODTrue, theTE); ODDisposePtr((Ptr)newStyle); } static void SetTextSize(TEHandle theTE, ODSShort fontSize) { TextStyle *newStyle = (TextStyle *) ODNewPtr(sizeof(TextStyle), kDefaultHeapID); (*newStyle).tsSize = fontSize; TESetStyle(doSize, newStyle, kODTrue, theTE); ODDisposePtr((Ptr)newStyle); } static void ShowAlert(Environment *ev, ODSShort alertID, ODFrame* frame) { ODSession* session = frame->GetStorageUnit(ev)->GetSession(ev); ODArbitrator* arbitrator = session->GetArbitrator(ev); // $$$$$ Should use notification manager if ( !IsFrontProcess() ) { SysBeep(2); return; } ODTypeToken modalFocus = session->Tokenize(ev, kODModalFocus); ODFrame* currentOwner = arbitrator->AcquireFocusOwner(ev, modalFocus); if ( (currentOwner == frame) || arbitrator->RequestFocus(ev, modalFocus, frame) ) { ODSLong savedRefNum; BeginUsingLibraryResources(savedRefNum); SetCursor(&(ODQDGlobals.arrow)); Alert(alertID, nil); ResetAlertStage(); EndUsingLibraryResources(savedRefNum); if ( (currentOwner != frame) ) arbitrator->TransferFocus(ev, modalFocus, frame, currentOwner); } else { SysBeep(2); } ODReleaseObject(ev, currentOwner); } static void ShowErrorAlert(Environment *ev, Str255 message, ODError error, ODFrame* frame) { Str255 numberString; NumToString(error, numberString); ParamText(message, numberString, nil, nil); ShowAlert(ev, kDragText_ErrorAlertID, frame); } static void ShowInfoAlert(Environment *ev, Str255 message, ODFrame* frame) { ParamText(message, nil, nil, nil); ShowAlert(ev, kDragText_InfoAlertID, frame); } static void WriteValueType(Environment *ev, ODStorageUnit* su, ODType prop, ODValueType kind, TEHandle theTEHandle, ODBoolean selectionOnly) { Handle textHandle; char textState; ODSShort selStart = (**theTEHandle).selStart; ODSShort selEnd = (**theTEHandle).selEnd; ODULong textStart; ODULong textSize; if ( selectionOnly ) { textStart = selStart; textSize = (selEnd < selStart ? 0 : (ODULong) (selEnd - selStart)); } else { textStart = 0; textSize = (**theTEHandle).teLength; } textHandle = (**theTEHandle).hText; textState = HGetState(textHandle); ODLockHandle((ODHandle) textHandle); if ( IsKind(kind, kODAppleTEXT) ) { SUFocusAndSetValue(ev, su, prop, kODAppleTEXT, (ODValue) ((*(char **)(textHandle)) + textStart), textSize); } else { if ( !selectionOnly ) TESetSelect(0, 32767, theTEHandle); StScrpHandle stylHandle = TEGetStyleScrapHandle(theTEHandle); ODULong stylSize = ODGetHandleSize((ODHandle) stylHandle); ODLockHandle((ODHandle) stylHandle); if ( IsKind(kind, kODApplestyl) ) { if ( textSize > 0 ) SUFocusAndSetValue(ev, su, prop, kODApplestyl, (ODValue) *stylHandle, stylSize); else SUFocusAndSetValue(ev, su, prop, kODApplestyl, (ODValue) kODNULL, 0); } else if ( IsKind(kind, kODApplestxt) ) { ODULong oldSize = 0; ODULong newSize = stylSize + textSize; SUForceFocus(ev, su, prop, kODApplestxt); oldSize = su->GetSize(ev); su->SetOffset(ev, 0); StorageUnitSetValue(su, ev, stylSize, (ODValue) *stylHandle); StorageUnitSetValue(su, ev, textSize, (ODValue) ((*(char **)(textHandle)) + textStart)); if ( oldSize > newSize ) su->DeleteValue(ev, oldSize - newSize); } ODUnlockHandle((ODHandle) stylHandle); ODDisposeHandle((ODHandle) stylHandle); if ( !selectionOnly ) TESetSelect(selStart, selEnd, theTEHandle); } HSetState(textHandle, textState); } ODStatic void ReadStyledText(Environment *ev, ODStorageUnit* su, Handle* textHandle, StScrpHandle* stylHandle) { *textHandle = kODNULL; *stylHandle = kODNULL; ODULong size = su->GetSize(ev); ODHandle tempHandle; ODValue value; // Compute the size of the style information short stylSize; StorageUnitGetValue(su, ev, sizeof(short), (ODValue) &stylSize); stylSize = (stylSize * sizeof(ScrpSTElement)) + sizeof(short); if ( stylSize > sizeof(short) ) { // Read the entire style record, including the first two bytes. su->SetOffset(ev, 0); tempHandle = ODNewHandle(stylSize); value = ODLockHandle(tempHandle); StorageUnitGetValue(su, ev, stylSize, value); ODUnlockHandle(tempHandle); *stylHandle = (StScrpHandle) tempHandle; } // read in TEXT if ( size > stylSize ) { ODULong textSize = size - stylSize; tempHandle = ODNewHandle(textSize); value = ODLockHandle(tempHandle); StorageUnitGetValue(su, ev, textSize, value); ODUnlockHandle(tempHandle); *textHandle = (Handle) tempHandle; } } ODStatic ODBoolean myValueNameSpaceGetODName(ODValueNameSpace* ns, Environment* ev, ODISOStr key, ODName** value) { ODByteArray ba; if (ns->GetEntry(ev, key, &ba)) { ODTradITextData* theIName = (ODTradITextData*)ODNewPtrClear(ba._length, kDefaultHeapID); ODBlockMove(ba._buffer, theIName, ba._length); ODDisposePtr( ba._buffer ); ODULong textLen = ba._length - sizeof(ODTradITextDataHeader); StringPtr thePString = (StringPtr)ODNewPtrClear(textLen+1); thePString[0] = textLen; ODBlockMove((ODPtr)theIName->theText, (ODPtr)&thePString[1], textLen ); *value = CreateITextPString(theIName->theScriptCode, theIName->theLangCode, thePString); ODDisposePtr( theIName ); ODDisposePtr( thePString ); return kODTrue; } else { *value = kODNULL; return kODFalse; } } //============================================================================== // DragText //============================================================================== //------------------------------------------------------------------------- // DragText: Externalize (Override) //------------------------------------------------------------------------- SOM_Scope void SOMLINK AppleTestDrag_DragTextExternalize(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","Externalize"); SOM_TRY parent_Externalize(somSelf,ev); if (_fDirty) { ODStorageUnit* partSU = somSelf->GetStorageUnit(ev); #ifdef SUPPORT_TESTDRAG_KIND ODULong suOffset; ODStorageUnitRef aSURef; ODFrame* aFrame; #endif #ifdef SUPPORT_TESTDRAG_KIND // fTestDragSU is null if internalized from a plain text part if ( _fTestDragSU == kODNULL ) _fTestDragSU = _fDraft->CreateStorageUnit(ev); #else if ( partSU->Exists(ev, kODPropContents, kODKindTestDrag, 0) ) { partSU->Focus(ev, kODPropContents, kODPosUndefined, kODKindTestDrag, 0, kODPosUndefined); partSU->Remove(ev); } #endif if ( _fDocument != kODNULL ) { // Write the text and style values to the content property WriteValueType(ev, partSU, kODPropContents, kODApplestxt, _fDocument->theTE, kODFalse); WriteValueType(ev, partSU, kODPropContents, kODAppleTEXT, _fDocument->theTE, kODFalse); #ifdef SUPPORT_TESTDRAG_KIND // Write the text and styl values to the TestDrag storage unit WriteValueType(ev, _fTestDragSU, kDragTextPropText, kODAppleTEXT, _fDocument->theTE, kODFalse); WriteValueType(ev, _fTestDragSU, kDragTextPropStyl, kODApplestyl, _fDocument->theTE, kODFalse); #endif } #ifdef SUPPORT_TESTDRAG_KIND // // Write out the display frame // OrderedCollectionIterator aIter(_fDisplayFrames); SUForceFocus(ev, _fTestDragSU, kODPropDisplayFrames, kODWeakStorageUnitRefs); ODULong oldValueSize = _fTestDragSU->GetSize(ev); suOffset = 0; for (aFrame = (ODFrame*)aIter.First(); aIter.IsNotComplete(); aFrame = (ODFrame*)aIter.Next(), suOffset+=sizeof(ODStorageUnitRef)) { _fTestDragSU->GetWeakStorageUnitRef(ev, aFrame->GetStorageUnit(ev)->GetID(ev), aSURef); _fTestDragSU->SetOffset(ev, suOffset); StorageUnitSetValue(_fTestDragSU, ev, sizeof(ODStorageUnitRef), aSURef); } if (oldValueSize > suOffset) _fTestDragSU->DeleteValue(ev, oldValueSize-suOffset); // // Write out the source and destination links // if (_fSrcLink.linkSource == (ODLinkSource*) kODNULL) { SURemoveProperty(ev, _fTestDragSU, kDragTextPropSourceLink); } else { SUForceFocus(ev, _fTestDragSU, kDragTextPropSourceLink, kDragTextValue); _fTestDragSU->GetStrongStorageUnitRef(ev, _fSrcLink.linkSource->GetStorageUnit(ev)->GetID(ev), aSURef); StorageUnitSetValue(_fTestDragSU, ev, sizeof(ODStorageUnitRef),aSURef); StorageUnitSetValue(_fTestDragSU, ev, sizeof(ODSShort), (ODValue) &_fSrcLink.start); StorageUnitSetValue(_fTestDragSU, ev, sizeof(ODSShort), (ODValue) &_fSrcLink.end); StorageUnitSetValue(_fTestDragSU, ev, sizeof(ODULong), (ODValue) &_fSrcLink.change); } if (_fDstLink.link == (ODLink*) kODNULL) { SURemoveProperty(ev, _fTestDragSU, kDragTextPropDestLink); } else { SUForceFocus(ev, _fTestDragSU, kDragTextPropDestLink, kDragTextValue); _fTestDragSU->GetStrongStorageUnitRef(ev, _fDstLink.link->GetStorageUnit(ev)->GetID(ev), aSURef); StorageUnitSetValue(_fTestDragSU, ev, sizeof(ODStorageUnitRef), aSURef); StorageUnitSetValue(_fTestDragSU, ev, sizeof(ODSShort), (ODValue) &_fDstLink.start); StorageUnitSetValue(_fTestDragSU, ev, sizeof(ODSShort), (ODValue) &_fDstLink.end); ODType kind = _fDstLink.info.kind; _fDstLink.info.kind = (ODType) ODISOStrLength(kind) + 1; StorageUnitSetValue(_fTestDragSU, ev, sizeof(ODLinkInfo), (ODValue) &_fDstLink.info); StorageUnitSetValue(_fTestDragSU, ev, (ODULong) _fDstLink.info.kind, (ODValue) kind); _fDstLink.info.kind = kind; } SUForceFocus(ev, partSU, kODPropContents, kODKindTestDrag); partSU->GetStrongStorageUnitRef(ev, _fTestDragSU->GetID(ev), aSURef); StorageUnitSetValue(partSU, ev, sizeof(ODStorageUnitRef), aSURef); #endif if (partSU->Exists(ev, kODPropContents, kODAppleFileTEXT, 0) ) { SURemoveValue(ev, partSU, kODPropContents, kODAppleFileTEXT); // $$$$$ Right thing to do? SURemoveValue(ev, partSU, kODPropContents, kODApplehfs); } _fDirty = kODFalse; } SOM_CATCH_ALL SOM_ENDTRY } //------------------------------------------------------------------------- // DragText: Release (Override) //------------------------------------------------------------------------- SOM_Scope void SOMLINK AppleTestDrag_DragTextRelease(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","Release"); parent_Release(somSelf, ev); if ( somSelf->GetRefCount(ev) == 0 ) somSelf->GetStorageUnit(ev)->GetDraft(ev)->ReleasePart(ev, _fPartWrapper); } //------------------------------------------------------------------------- // DragText: Release All (Override) //------------------------------------------------------------------------- SOM_Scope void SOMLINK AppleTestDrag_DragTextReleaseAll(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ReleaseAll"); SOM_TRY // PRINT("DragText::ReleaseAll: draft refcount is %d\n", somSelf->GetStorageUnit(ev)->GetDraft(ev)->GetRefCount(ev)); ODReleaseObject(ev,_fSrcLink.linkSource); ODReleaseObject(ev,_fDstLink.link); ODReleaseObject(ev,_fTestDragSU); AppleTestDrag_DragText_parent_ODPart_ReleaseAll(somSelf,ev); SOM_CATCH_ALL SOM_ENDTRY } //------------------------------------------------------------------------- // From DragAndDrop protocol //------------------------------------------------------------------------- SOM_Scope void SOMLINK AppleTestDrag_DragTextFulfillPromise(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnitView* promiseSUView) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","FulfillPromise"); #ifdef TRYOUT_PROMISE ODStorageUnit* su = promiseSUView->GetStorageUnit(ev)->GetDraft(ev)->CreateStorageUnit(ev); su->Release(ev); promiseSUView->Remove(ev); #endif #ifdef TRYOUT_PROMISE_FILE ODValueType valueType = promiseSUView->GetType(ev); if (ODISOStrEqual(valueType, kODHFSPromise)) { ODByteArray ba; short fileRefNum = 0; ODVolatile(ba); ODVolatile(fileRefNum); SOM_TRY const Str63 fileName = "\pDragText (TEXT)"; FSSpec dropFSSpec; StorageUnitViewGetValue(promiseSUView, ev, sizeof(FSSpec), &dropFSSpec); ODBlockMove(fileName, &(dropFSSpec.name), fileName[0]+ 1); promiseSUView->SetOffset(ev, 0); ba._buffer = kODNULL; ODStorageUnit* su = promiseSUView->GetStorageUnit(ev); su->Focus(ev, kODPropContents, kODPosUndefined, kODAppleTEXT, 0, kODPosUndefined); long size = su->GetSize(ev); size = su->GetValue(ev, size, &ba); OSErr err; if (((err = FSpCreate(&dropFSSpec, 'ttxt','TEXT', smSystemScript)) == noErr) && ((err = FSpOpenDF(&dropFSSpec, fsRdWrPerm, &fileRefNum)) == noErr) && ((err = FSWrite(fileRefNum, &size, ba._buffer)) == noErr) && ((err = FSClose(fileRefNum)) == noErr)) { StorageUnitViewSetValue(promiseSUView, ev, sizeof(FSSpec), &dropFSSpec); } else { ODULong size = promiseSUView->GetSize(ev); promiseSUView->DeleteValue(ev, size); } ODDisposePtr(ba._buffer); SOM_CATCH_ALL if (fileRefNum) FSClose(fileRefNum); ODDisposePtr(ba._buffer); ODSetSOMException(ev, 0); SOM_ENDTRY } ODDisposePtr(valueType); #endif /* StScrpHandle theStyl; theStyl = TEGetStyleScrapHandle(_fDocument->theTE); if (theStyl) { ODLockHandle((ODHandle) theStyl); StorageUnitSetValue(promiseSUView, ev, ODGetHandleSize((ODHandle) theStyl), (ODValue)*theStyl); ODUnlockHandle((ODHandle) theStyl); ODDisposeHandle((ODHandle) theStyl); } */ } SOM_Scope void SOMLINK AppleTestDrag_DragTextDropCompleted(AppleTestDrag_DragText *somSelf, Environment *ev, ODPart* destPart, ODDropResult dropResult) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DropCompleted"); ODUnused(destPart); ODUnused(dropResult); } ODStatic void PrintContentKinds(Environment *ev, ODStorageUnit *su) { if ( su->Exists(ev, kODPropContents, kODNULL, 0) ) { su->Focus(ev, kODPropContents, kODPosUndefined, kODTypeAll, 0, kODPosUndefined); ODULong numValues = su->CountValues(ev); ODULong kindIndex; for (kindIndex = 0; kindIndex < numValues; kindIndex++) { su->Focus(ev, kODPropContents, kODPosUndefined, kODTypeAll, 0, kODPosNextSib); ODValueType kind = su->GetType(ev); somPrintf("Content type: %s\n", kind); ODDisposePtr(kind); } } } SOM_Scope ODDragResult SOMLINK AppleTestDrag_DragTextDragEnter(AppleTestDrag_DragText *somSelf, Environment *ev, ODDragItemIterator* dragInfo, ODFacet* facet, ODPoint* where) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DragEnter"); ODUnused(where); SOM_TRY ODStorageUnit *dragSU; if ( facet->GetFrame(ev)->GetLinkStatus(ev) == kODInLinkDestination ) { _fDocument->canAccept = kODFalse; } else { _fDocument->canAccept = true; for (dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev)) { #ifdef ODDebug PRINT("DragText: DragEnter looking for content values\n"); PrintContentKinds(ev, dragSU); #endif if ( !dragSU->Exists(ev, kODPropContents, kODAppleTEXT, 0) ) { if( !dragSU->Exists(ev, kODPropContents, kODKindTestDrag, 0) ) { if ( !dragSU->Exists(ev, kODPropContents, kODAppleFileTEXT, 0) || !dragSU->Exists(ev, kODPropContents, kODApplehfs, 0) ) { _fDocument->canAccept = kODFalse; break; } } } } _fDocument->caretTime = TickCount(); _fDocument->caretOffset = _fDocument->lastOffset = _fDocument->insertPosition = -1; _fDocument->caretShow = true; _fDocument->cursorInContent = false; } return _fDocument->canAccept; SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } SOM_Scope ODDragResult SOMLINK AppleTestDrag_DragTextDragWithin(AppleTestDrag_DragText *somSelf, Environment *ev, ODDragItemIterator* dragInfo, ODFacet* facet, ODPoint* where) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DragWithin"); ODUnused(dragInfo); SOM_TRY short offset; long theTime = TickCount(); GrafPtr savedPort; ODULong attributes; DragReference theDrag; RgnHandle dragHilite; ODPoint windowWhere = *where; { TempODTransform wfTform = facet->AcquireWindowFrameTransform(ev, kODNULL); wfTform->TransformPoint(ev, &windowWhere); } if (!_fDocument->canAccept) return kODFalse; GetPort(&savedPort); SetPort(_fDocument->theWindow); somSelf->ClipThis(ev, facet); attributes = _fSession->GetDragAndDrop(ev)->GetDragAttributes(ev); theDrag = _fSession->GetDragAndDrop(ev)->GetDragReference(ev); if (PtInRect(windowWhere.AsQDPoint(), &(**(_fDocument->theTE)).viewRect)) { if (!_fDocument->cursorInContent) { dragHilite = ODNewRgn(); RectRgn(dragHilite, &(**(_fDocument->theTE)).viewRect); ShowDragHilite(theDrag, dragHilite, true); } _fDocument->cursorInContent = true; offset = TEGetOffset(windowWhere.AsQDPoint(), _fDocument->theTE); if ((TEIsFrontOfLine(offset, _fDocument->theTE)) && (offset) && ((*((char **)((**(_fDocument->theTE)).hText)))[offset - 1] != 0x0D) && (ff(TEGetPoint(offset - 1, _fDocument->theTE).h) < windowWhere.x)) offset--; // If this is the source frame, do not allow tracking through the selection if ((attributes & kODDragIsInSourceFrame) && (offset >= (**(_fDocument->theTE)).selStart) && (offset <= (**(_fDocument->theTE)).selEnd)) offset = -1; // Do not set insertion point within a link destination if ( (offset > _fDstLink.start) && (offset < _fDstLink.end) ) offset = _fDocument->insertPosition; _fDocument->insertPosition = offset; // // Reset flashing counter if the offset has moved. // if (offset != _fDocument->lastOffset) { _fDocument->caretTime = theTime; _fDocument->caretShow = true; } _fDocument->lastOffset = offset; // // Flash caret. // if (theTime - _fDocument->caretTime > GetCaretTime()) { _fDocument->caretShow = !_fDocument->caretShow; _fDocument->caretTime = theTime; } if (!_fDocument->caretShow) offset = -1; // // If offset has changed, move caret on screen. // if (offset != _fDocument->caretOffset) { if (offset != -1) DrawCaret(offset, _fDocument->theTE, 0L); if (_fDocument->caretOffset != -1) DrawCaret(_fDocument->caretOffset, _fDocument->theTE, 0L); } _fDocument->caretOffset = offset; } else { if (_fDocument->cursorInContent) { HideDragHilite(theDrag); } _fDocument->cursorInContent = false; _fDocument->lastOffset = -1; _fDocument->insertPosition = -1; } SetPort(savedPort); return kODTrue; SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } SOM_Scope void SOMLINK AppleTestDrag_DragTextDragLeave(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet, ODPoint* where) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DragLeave"); ODUnused(facet); ODUnused(where); SOM_TRY GrafPtr savedPort; ODULong attributes; DragReference theDrag; if (!_fDocument->canAccept) return; GetPort(&savedPort); SetPort(_fDocument->theWindow); theDrag = _fSession->GetDragAndDrop(ev)->GetDragReference(ev); attributes = _fSession->GetDragAndDrop(ev)->GetDragAttributes(ev); // // If the caret is on the screen, remove it. // if (_fDocument->caretOffset != -1) { DrawCaret(_fDocument->caretOffset, _fDocument->theTE, 0L); _fDocument->caretOffset = -1; } // // Remove frame highlighting, if showing. // if (_fDocument->cursorInContent) { HideDragHilite(theDrag); } SetPort(savedPort); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope ODDropResult SOMLINK AppleTestDrag_DragTextDrop(AppleTestDrag_DragText *somSelf, Environment *ev, ODDragItemIterator* dropInfo, ODFacet* facet, ODPoint* where) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","Drop"); SOM_TRY GrafPtr savedPort; Size textSize, stylSize; short selStart, selEnd, moveText; //WindowOffscreen *theOffscreen; Rect theRect, srcRect; Point thePoint; ODULong attributes; DragReference theDrag; ODStorageUnit *dropSU; OSErr error = noErr; short fileRefNum = 0; ODPtr fileData = kODNULL; ODPtr textData = kODNULL; TEHandle tempTE = kODNULL; StScrpHandle stylHandle = kODNULL; ODDropResult dropResult = kODDropCopy; ODBoolean done = kODFalse; // $$$$$ OBSOLETE: Volatile(fileData); // $$$$$ OBSOLETE: Volatile(textData); // $$$$$ OBSOLETE: Volatile(stylHandle); // $$$$$ OBSOLETE: Volatile(tempTE); // $$$$$ OBSOLETE: Volatile(fileRefNum); // $$$$$ OBSOLETE: Volatile(exit); if ((!_fDocument->canAccept) || (_fDocument->insertPosition == -1)) return(kODDropFail); if ( OneDragItem(ev, dropInfo) ) { // Call DropOneItem unless the storage unit contains an Applehfs value, // in which case just let the "old" code handle it. if ( !(dropInfo->First(ev)->Exists(ev, kODPropContents, kODApplehfs, 0)) ) return somSelf->DropOneItem(ev, dropInfo->First(ev), facet, where); } GetPort(&savedPort); SetPort(_fDocument->theWindow); attributes = _fSession->GetDragAndDrop(ev)->GetDragAttributes(ev); moveText = (attributes & kODDragIsInSourceFrame) && (attributes & kODDropIsMove); if (attributes & kODDropIsMove) dropResult = kODDropMove; theDrag = _fSession->GetDragAndDrop(ev)->GetDragReference(ev); // // Loop through all of the drag items contained in this drag and collect the text // into the tempTE record. // SetRect(&theRect, 0, 0, 0, 0); tempTE = TEStyleNew(&theRect, &theRect); TRY for (dropSU = dropInfo->First(ev); dropSU && !done ; dropSU = dropInfo->Next(ev)) { // // If canAccept is true then 'TEXT' or 'hfs' must be present in all items // if (dropSU->Exists(ev, kODPropContents, kODAppleTEXT, 0)) { dropSU->Focus(ev, kODPropContents, kODPosUndefined, kODAppleTEXT, 0, kODPosUndefined); textSize = dropSU->GetSize(ev); textData = ODNewPtr(textSize, kDefaultHeapID); StorageUnitGetValue(dropSU, ev, textSize, (ODValue)textData); // // Check for optional styl data for the TEXT. // if (dropSU->Exists(ev, kODPropContents, kODApplestyl, 0)) { dropSU->Focus(ev, kODPropContents, kODPosUndefined, kODApplestyl, 0, kODPosUndefined); stylSize = dropSU->GetSize(ev); stylHandle = (StScrpHandle) ODNewHandle(stylSize); StorageUnitGetValue(dropSU, ev, stylSize, (ODValue) ODLockHandle((ODHandle) stylHandle)); ODUnlockHandle((ODHandle) stylHandle); } done = kODTrue; } else if (dropSU->Exists(ev, kODPropContents, kODApplehfs, 0)) { FSSpec fileSpec; if ( GetFSSpecFromHFSProperty(ev, dropSU, &fileSpec) ) { // $$$$$ Should modify to use InsertFromTextFile. THROW_IF_ERROR(FSpOpenDF(&fileSpec, fsRdPerm, &fileRefNum)); THROW_IF_ERROR(GetEOF(fileRefNum,&textSize)); if (textSize == 0) THROW(kODErrUndefined); else if ( textSize < 0 ) THROW(kDragTextBogusTextSize); else if ( textSize + (**tempTE).teLength + (**(_fDocument->theTE)).teLength > kMaxTextSize ) THROW(kDragTextErrTooMuchText); textData = ODNewPtr(textSize, kDefaultHeapID); THROW_IF_ERROR(SetFPos(fileRefNum,fsFromStart,0)); THROW_IF_ERROR(FSRead(fileRefNum,&textSize,textData)); THROW_IF_ERROR(FSClose(fileRefNum)); done = kODTrue; } else THROW(kDragTextErrCantReadTEXTFile); } // // Insert this drag item's text into the tempTE. // // TESetSelect(32767, 32767, tempTE); TEStyleInsert(textData, textSize, stylHandle, tempTE); if (textData) ODDisposePtr(textData); if (stylHandle) ODDisposeHandle((ODHandle) stylHandle); } CATCH_ALL if ( ErrorCode() == kDragTextErrTooMuchText ) ShowInfoAlert(ev, "\pToo much text to drop here.", facet->GetFrame(ev)); else ShowErrorAlert(ev, "\pError during drop.", ErrorCode(), facet->GetFrame(ev)); if (tempTE != kODNULL) TEDispose(tempTE); if (fileData != kODNULL) ODDisposePtr(fileData); if (stylHandle != kODNULL) ODDisposeHandle((ODHandle) stylHandle); if (fileRefNum != 0) FSClose(fileRefNum); dropResult = kODDropFail; ENDTRY if ( (dropResult == kODDropCopy) || (dropResult == kODDropMove) ) { // // Pull the TEXT and styl data out of the tempTE handle. // textSize = (**tempTE).teLength; textData = ODNewPtr(textSize, kDefaultHeapID); if (!textData) { WARN("NewPtr error"); TEDispose(tempTE); return(kODDropFail); } ODBlockMove(*(**tempTE).hText, textData, textSize); TESetSelect(0, 32767, tempTE); stylHandle = TEGetStyleScrapHandle(tempTE); TEDispose(tempTE); if (textSize) { // // If the caret or highlighting is on the screen, remove it/them. // if (_fDocument->caretOffset != -1) { DrawCaret(_fDocument->caretOffset, _fDocument->theTE, 0L); _fDocument->caretOffset = -1; } if (_fDocument->cursorInContent) { HideDragHilite(theDrag); } // // If the frame is not active, must activate TE before inserting // text or the background hilite will not update correctly. // if (!_fDocument->frameIsActive) TEActivate(_fDocument->theTE); // // If this window is also the sender, delete source selection if no option key. // if (moveText) { selStart = (**(_fDocument->theTE)).selStart; selEnd = (**(_fDocument->theTE)).selEnd; if ( WhiteSpaceAtOffset(selStart - 1, _fDocument->theTE) && !WhiteSpaceAtOffset(selStart, _fDocument->theTE) && !WhiteSpaceAtOffset(selEnd - 1, _fDocument->theTE) && WhiteSpaceAtOffset(selEnd, _fDocument->theTE)) { if (GetCharAtOffset(selEnd, _fDocument->theTE) == ' ') (**(_fDocument->theTE)).selEnd++; } if (_fDocument->insertPosition > selStart) { _fDocument->insertPosition -= (ev, (**(_fDocument->theTE)).selEnd - (**(_fDocument->theTE)).selStart); } srcRect = (**_fDocument->hiliteRgn).rgnBBox; TEDelete(_fDocument->theTE); } InsertTextAtOffset(_fDocument->insertPosition, (char*) textData, textSize, stylHandle, _fDocument->theTE); TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); if (moveText) { theRect = (**_fDocument->hiliteRgn).rgnBBox; SetPt(&thePoint,0,0); LocalToGlobal(&thePoint); OffsetRect(&srcRect, thePoint.h, thePoint.v); OffsetRect(&theRect, thePoint.h, thePoint.v); ZoomRects(&srcRect, &theRect, 12, zoomDecelerate); } _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); } if (textData) ODDisposePtr(textData); if (fileData) ODDisposePtr(fileData); if (stylHandle) ODDisposeHandle((ODHandle) stylHandle); // // Undo the TEActivate, if needed. // if (!_fDocument->frameIsActive) TEDeactivate(_fDocument->theTE); // // Signal the draw method to update the scroll bars // _fFrameShapeChanged = true; facet->Invalidate(ev, kODNULL, kODNULL); } else { // Remove the drop hilite if (_fDocument->cursorInContent) HideDragHilite(theDrag); } SetPort(savedPort); return dropResult; SOM_CATCH_ALL SOM_ENDTRY return kODDropFail; } SOM_Scope ODDropResult SOMLINK AppleTestDrag_DragTextDropOneItem(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* dropSU, ODFacet* facet, ODPoint* where) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DropOneItem"); DragReference theDrag; ODDropResult dropResult; ODBoolean isMove; ODBoolean pasteAs = kODFalse; ODCloneKind cloneKind; theDrag = _fSession->GetDragAndDrop(ev)->GetDragReference(ev); ODULong attributes = _fSession->GetDragAndDrop(ev)->GetDragAttributes(ev); isMove = attributes & kODDropIsMove; pasteAs = attributes & kODDropIsPasteAs; cloneKind = ( isMove ? kODCloneDropMove : kODCloneDropCopy ); dropResult = ( isMove ? kODDropMove : kODDropCopy ); TRY #ifdef SHOW_DROP_PASTE_AS_DIALOG if ( pasteAs ) { ODPasteAsResult pasteAsRslt; pasteAsRslt.selectedKind = kODNULL; pasteAsRslt.translateKind = kODNULL; pasteAsRslt.editor = kODNULL; TempODPasteAsResult tempResult = &pasteAsRslt; // DMc: ensure deletion of selectedKind, translateKind, editor // $$$$$ This test that the drop originated with this part // fails if there are more than one display frame. ODULong attributes = _fSession->GetDragAndDrop(ev)->GetDragAttributes(ev); ODBoolean isMyContent = (attributes & kODDragIsInSourceFrame); ODBoolean enablePasteLink = /* (!isMove) && */ (somSelf->CanPasteLink(ev, dropSU, isMyContent, _fDocument->insertPosition, _fDocument->insertPosition)); GrafPtr savePort; GetPort(&savePort); // $$$$$ ShowPasteAsDialog changes the current port if ( _fSession->GetDragAndDrop(ev)->ShowPasteAsDialog(ev, enablePasteLink, kODPasteAsMergeOnly, facet, _fSession->Tokenize(ev, kODViewAsFrame), dropSU, &pasteAsRslt) ) { somSelf->ActivateFrame(ev, facet->GetFrame(ev)); if ( pasteAsRslt.pasteLinkSetting != kODFalse ) { somSelf->DoDropPasteLink(ev, dropSU, pasteAsRslt.selectedKind, facet, where); dropResult = kODDropCopy; } else somSelf->DoDropPaste(ev, dropSU, cloneKind, pasteAsRslt.selectedKind, facet, where); } else { // User cancelled the drop dropResult = kODDropFail; // Remove the drop hilight SetPort(savePort); // $$$$$ ShowPasteAsDialog changes the current port HideDragHilite(theDrag); } } else #endif { somSelf->ActivateFrame(ev, facet->GetFrame(ev)); somSelf->DoDropPaste(ev, dropSU, cloneKind, (ODType) kODNULL, facet, where); } CATCH_ALL WARN("DropOneItem: Drop failed."); dropResult = kODDropFail; ENDTRY return dropResult; } SOM_Scope void SOMLINK AppleTestDrag_DragTextCommonDropProlog(AppleTestDrag_DragText *somSelf, Environment *ev, ODCloneKind cloneKind) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CommonDropProlog"); SOM_TRY ODULong attributes = _fSession->GetDragAndDrop(ev)->GetDragAttributes(ev); DragReference theDrag = _fSession->GetDragAndDrop(ev)->GetDragReference(ev); // If the caret or highlighting is on the screen, remove it/them. if (_fDocument->caretOffset != -1) { DrawCaret(_fDocument->caretOffset, _fDocument->theTE, 0L); _fDocument->caretOffset = -1; } if (_fDocument->cursorInContent) { HideDragHilite(theDrag); } // If the frame is not active, must activate TE before inserting // text or the background hilite will not update correctly. if (!_fDocument->frameIsActive) TEActivate(_fDocument->theTE); // If this is a move within the same part, abandon a moved link source or // destination now. This has to be done only because this part supports only // one link source and one link destination. if ( (cloneKind == kODCloneDropMove) && (attributes & kODDragIsInSourceFrame) ) { // If the selection includes a link, assume its being moved. ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; if ( _fSrcLink.linkSource != (ODLinkSource*) kODNULL ) { if ( IncludedInRange(_fSrcLink.start, _fSrcLink.end, selStart, selEnd) ) { // Since we're just moving the source of the link, just allow // us to make a new one. _fSrcLink.linkSource->Release(ev); _fSrcLink.linkSource = (ODLinkSource*) kODNULL; _fSrcLink.start = -1; _fSrcLink.end = -1; _fSrcLink.change = kODUnknownUpdate; } } if ( _fDstLink.link != (ODLink*) kODNULL ) { if ( IncludedInRange(_fDstLink.start, _fDstLink.end, selStart, selEnd) ) { if ( _fDstLink.info.autoUpdate ) _fDstLink.link->UnregisterDependent(ev, _fPartWrapper); _fDstLink.link->Release(ev); _fDstLink.link = (ODLink*) kODNULL; _fDstLink.start = -1; _fDstLink.end = -1; } } } // Change the selection to the insertion position. TESetSelect(_fDocument->insertPosition, _fDocument->insertPosition, _fDocument->theTE); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextDoDropPaste(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* dropSU, ODCloneKind cloneKind, ODType desiredKind, ODFacet* facet, ODPoint* where) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoDropPaste"); ODUnused(where); SOM_TRY GrafPtr savedPort; GetPort(&savedPort); SetPort(_fDocument->theWindow); somSelf->CommonDropProlog(ev, cloneKind); ODSShort dropStart, dropEnd; TRY dropStart = (**(_fDocument->theTE)).selStart; #ifdef SUPPORT_TESTDRAG_KIND if ( PasteThisKind (ev, dropSU, kODKindTestDrag, desiredKind) ) { somSelf->OpenWhitespace(ev, dropSU, kODKindTestDrag); somSelf->IncorporateTestDragContent(ev, dropSU, _fSession->UniqueUpdateID(ev), cloneKind); } else #endif if ( PasteThisKind (ev, dropSU, kODApplestxt, desiredKind) || PasteThisKind (ev, dropSU, kODApplestyl, desiredKind) ) { somSelf->OpenWhitespace(ev, dropSU, kODAppleTEXT); somSelf->IncorporateStyledTextContent(ev, dropSU, _fSession->UniqueUpdateID(ev)); } else if ( PasteThisKind (ev, dropSU, kODAppleTEXT, desiredKind) ) { somSelf->OpenWhitespace(ev, dropSU, kODAppleTEXT); somSelf->IncorporateTextContent(ev, dropSU, _fSession->UniqueUpdateID(ev)); } dropEnd = (**(_fDocument->theTE)).selEnd; TESetSelect(dropStart, dropEnd, _fDocument->theTE); TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); CATCH_ALL // Undo the TEActivate, if needed. if (!_fDocument->frameIsActive) TEDeactivate(_fDocument->theTE); RERAISE; ENDTRY // Undo the TEActivate, if needed. if (!_fDocument->frameIsActive) TEDeactivate(_fDocument->theTE); // Signal the draw method to update the scroll bars _fFrameShapeChanged = true; facet->Invalidate(ev, kODNULL, kODNULL); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextDoDropPasteLink(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* dropSU, ODType desiredKind, ODFacet* facet, ODPoint* where) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoDropPasteLink"); ODUnused(facet); ODUnused(where); SOM_TRY GrafPtr savedPort; GetPort(&savedPort); SetPort(_fDocument->theWindow); somSelf->CommonDropProlog(ev, kODCloneDropCopy); ODSShort dropStart = (**(_fDocument->theTE)).selStart; somSelf->PasteLinkFromSU(ev, facet->GetFrame(ev), desiredKind, dropSU); // If the source of the link was from this part, remove any link spec from the clipboard // $$$$$ If the link spec on the clipboard happens to refer to the same content as the // link just created, there is no need to remove it. somSelf->RemoveLinkSpec(ev); ODSShort dropEnd = (**(_fDocument->theTE)).selEnd; TESetSelect(dropStart, dropEnd, _fDocument->theTE); // Undo the TEActivate, if needed. if (!_fDocument->frameIsActive) TEDeactivate(_fDocument->theTE); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextOpenWhitespace(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* su, ODValueType kind) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","OpenWhitespace"); SOM_TRY char firstChar = PeekIntoValue(ev, su, kind, 0); char lastChar = PeekIntoValue(ev, su, kind, -1); somSelf->InsertWhitespace(ev, firstChar, lastChar); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextInsertWhitespace(AppleTestDrag_DragText *somSelf, Environment *ev, char firstChar, char lastChar) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","InsertWhitespace"); SOM_TRY TEHandle theTE = _fDocument->theTE; ODSShort selStart = (**theTE).selStart; ODSShort selEnd = (**theTE).selEnd; // // If inserting at the end of a word and the selection does not begin with // a space, insert a space before the insertion. // if (!WhiteSpaceAtOffset(selStart - 1, theTE) && WhiteSpaceAtOffset(selStart, theTE) && !WhiteSpace(firstChar)) { TESetSelect(selStart, selStart, theTE); TEKey(' ', theTE); somSelf->AdjustLinks(ev, selStart, selStart, selStart+1, _fSession->UniqueUpdateID(ev)); selStart++; selEnd++; } // // If inserting at the beginning of a word and the selection does not end // with a space, insert a space after the insertion. // if ( WhiteSpaceAtOffset(selEnd - 1, theTE) && !WhiteSpaceAtOffset(selEnd, theTE) && !WhiteSpace(lastChar)) { TESetSelect(selEnd, selEnd, theTE); TEKey(' ', theTE); somSelf->AdjustLinks(ev, selEnd, selEnd, selEnd+1, _fSession->UniqueUpdateID(ev)); } // Restore the selection TESetSelect(selStart, selEnd, theTE); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextDisplayFrameAdded(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DisplayFrameAdded"); SOM_TRY // If the first display frame is being added, register any link destination if (_fDisplayFrames->Count() == 0) { if ( _fDstLink.link != ((ODLink*) kODNULL) ) if ( _fDstLink.info.autoUpdate ) _fDstLink.link->RegisterDependent(ev, _fPartWrapper, _fDstLink.info.change); } if (frame->GetViewType(ev) == kODNullTypeToken) // if frame view is set don't change it frame->SetViewType(ev, _fSession->Tokenize(ev, kODViewAsFrame)); // if not, make it viewasframe frame->SetDroppable(ev, kODTrue); _fDisplayFrames->AddLast(frame); frame->Acquire(ev); if ( frame->IsRoot(ev) ) _fNeedsFoci = kODTrue; SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextDisplayFrameRemoved(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DisplayFrameRemoved"); SOM_TRY if (_fDisplayFrames->Contains(frame)) { somSelf->DeactivateFrame(ev, frame); _fDisplayFrames->Remove(frame); frame->Release(ev); // If the last display frame was removed, unregister any link destination if (_fDisplayFrames->Count() == 0) { if ( _fDstLink.link != ((ODLink*) kODNULL) ) if ( _fDstLink.info.autoUpdate ) _fDstLink.link->UnregisterDependent(ev, _fPartWrapper); } } else { THROW(kODErrInvalidFrame); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextDisplayFrameConnected(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DisplayFrameConnected"); SOM_TRY frame->SetDroppable(ev, kODTrue); if ( !_fDisplayFrames->Contains(frame) ) { frame->Acquire(ev); _fDisplayFrames->AddLast((ElementType) frame); } if ( frame->IsRoot(ev) ) _fNeedsFoci = kODTrue; SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextDisplayFrameClosed(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DisplayFrameClosed"); SOM_TRY if (_fDisplayFrames->Contains(frame)) { somSelf->DeactivateFrame(ev, frame); _fDisplayFrames->Remove(frame); frame->Release(ev); // If the last display frame was closed, unregister any link destination if (_fDisplayFrames->Count() == 0) { if ( _fDstLink.link != ((ODLink*) kODNULL) ) if ( _fDstLink.info.autoUpdate ) _fDstLink.link->UnregisterDependent(ev, _fPartWrapper); } } else { THROW(kODErrInvalidFrame); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextGeometryChanged(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet, ODBoolean clipShapeChanged, ODBoolean externalTransformChanged) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","GeometryChanged"); ODUnused(facet); SOM_TRY somSelf->PositionDocumentParts(ev); somSelf->AdjustScrollBar(ev); TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); _fFrameShapeChanged = false; SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextDraw(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet, ODShape* invalidShape) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","Draw"); ODUnused(invalidShape); SOM_TRY ODPoint xForm; ODShape* clipShape = kODNULL; ODShape* frameShape = kODNULL; RgnHandle clipRgn, saveClip, frameRgn; Rect bounds; GrafPtr savedQDPort, oldTEPort; ODBoolean drawing = facet->GetCanvas(ev)->IsDynamic(ev); if (facet) { GetPort(&savedQDPort); if (drawing) { SetPort(facet->GetCanvas(ev)->GetQDPort(ev)); } else { oldTEPort = (**(_fDocument->theTE)).inPort; (**(_fDocument->theTE)).inPort = facet->GetCanvas(ev)->GetQDPort(ev); } SetOrigin(0,0); xForm = GetAggregateTranslation(ev, facet); frameShape = facet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL); frameRgn = frameShape->GetQDRegion(ev); clipShape = facet->AcquireClipShape(ev, kODNULL); clipRgn = clipShape->CopyQDRegion(ev); saveClip = ODNewRgn(); GetClip(saveClip); bounds = (**frameRgn).rgnBBox; OffsetRect(&bounds, xForm.IntX(), xForm.IntY()); OffsetRgn(clipRgn, xForm.IntX(), xForm.IntY()); SetClip(clipRgn); EraseRect(&(**clipRgn).rgnBBox); // Draw the frame Rect theRect = (**(_fDocument->theTE)).viewRect; PenSize(1, 1); InsetRect(&theRect, -1, -1); PenPat(&ODQDGlobals.white); FrameRect(&theRect); InsetRect(&theRect, -1, -1); PenPat(&ODQDGlobals.black); FrameRect(&theRect); PenNormal(); if ( drawing ) DrawControls(_fDocument->theWindow); TEUpdate(&bounds, _fDocument->theTE); #ifdef SHOW_LINK_BORDERS _fLinkBorderStyle = kLinkBorderOff; _fTimeBorderOff = TickCount(); #endif if (!drawing) // restore the window port (**(_fDocument->theTE)).inPort = oldTEPort; SetPort(savedQDPort); SetClip(saveClip); if (frameShape) frameShape->Release(ev); if (clipShape) clipShape->Release(ev); ODDisposeHandle((Handle)saveClip); ODDisposeHandle((Handle)clipRgn); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextShowLinkBorder(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, LinkBorderStyle borderStyle) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ShowLinkBorder"); SOM_TRY if ( _fLinkBorderStyle != borderStyle ) { ODFrameFacetIterator* fiter = frame->CreateFacetIterator(ev); if ( _fSrcLink.linkSource != (ODLinkSource*) kODNULL ) { #ifdef DEBUG_LINK_BORDERS PRINT("DragText %d: Show link source border\n", somSelf->GetID(ev)); #endif DrawLinkBorder(ev, fiter->First(ev), _fSrcLink.start, _fSrcLink.end, _fDocument->theTE, borderStyle); } if ( _fDstLink.link != ((ODLink*) kODNULL) ) { #ifdef DEBUG_LINK_BORDERS PRINT("DragText %d: Show link border\n", somSelf->GetID(ev)); #endif DrawLinkBorder(ev, fiter->First(ev), _fDstLink.start, _fDstLink.end, _fDocument->theTE, borderStyle); } ODDeleteObject(fiter); _fLinkBorderStyle = borderStyle; } if ( borderStyle == kLinkBorderOff ) _fTimeBorderOff = TickCount(); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextHandleEvent(AppleTestDrag_DragText *somSelf, Environment *ev, ODEventData* event, ODFrame* frame, ODFacet* facet, ODEventInfo* eventInfo) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","HandleEvent"); SOM_TRY ODBoolean handled = kODFalse; switch (event->what) { case nullEvent: somSelf->Idle(ev, frame); break; case mouseDown: case kODEvtBGMouseDown: { // PRINT("DragText %d: HandleEvent: mouseDown\n", somSelf->GetID(ev)); Point windowPoint = event->where; // GrafPtr curPort; // GetPort(&curPort); // SetPort(facet->AcquireWindow(ev)->GetPlatformWindow(ev)); SetOrigin(0,0); GlobalToLocal(&windowPoint); ODPoint windowODPoint(windowPoint); handled = somSelf->HandleMouseDown(ev, facet, &windowODPoint, event); // SetPort(curPort); } break; case kODEvtMouseDownEmbedded: { Point windowPoint = event->where; // GrafPtr curPort; // GetPort(&curPort); // SetPort(facet->AcquireWindow(ev)->GetPlatformWindow(ev)); SetOrigin(0,0); GlobalToLocal(&windowPoint); ODPoint windowODPoint(windowPoint); handled = somSelf->HandleMouseDownInBorder(ev, facet, (ODFacet*) event->message, &windowODPoint, event); // SetPort(curPort); } break; case mouseUp: // PRINT("DragText %d: HandleEvent: mouseUp\n", somSelf->GetID(ev)); if ( !_fHasFoci ) { somSelf->ActivateFrame(ev, facet->GetFrame(ev)); GrafPtr curPort; GetPort(&curPort); SetPort(_fDocument->theWindow); Point thePoint = event->where; GlobalToLocal(&thePoint); TEClick(thePoint, false, _fDocument->theTE); somSelf->ExpandSelectionAroundLink(ev); SetPort(curPort); } handled = kODTrue; break; case keyDown: case autoKey: handled = somSelf->HandleKeyDown(ev, frame, event); break; case activateEvt: handled = kODTrue; if ((event->modifiers & activeFlag) != 0) { // PRINT("DragText %d: HandleEvent: Activate\n", somSelf->GetID(ev)); somSelf->ActivatingWindow(ev, frame); } else { // PRINT("DragText %d: HandleEvent: Deactivate\n", somSelf->GetID(ev)); somSelf->DeactivatingWindow(ev, frame); } break; case keyUp: break; case osEvt: { const short kSuspendResumeMessage = 0x01; // Resume vs. suspend mask unsigned char typeOSEvent = (unsigned char) (event->message >> 24) & 0x00FF; if ( typeOSEvent == kSuspendResumeMessage ) { const short kResumeMask = 0x01; // High byte suspend/resume event ODBoolean goingToBackground = (event->message & kResumeMask) == 0; if ( goingToBackground ) somSelf->DeactivatingWindow(ev, frame); else somSelf->ActivatingWindow(ev, frame); } } break; case kHighLevelEvent: break; case kODEvtMenu: handled = somSelf->HandleMenuEvent(ev, frame, event); break; case kODEvtMouseEnter: #if ODDebug && ODDebugCursor //PRINT("MouseEnter %d %d\n",eventInfo->where.IntX(),eventInfo->where.IntY()); #endif handled = kODTrue; break; case kODEvtMouseWithin: #if ODDebug && ODDebugCursor PRINT("MouseWithin Frame X: %d Y: %d\n",eventInfo->where.IntX(),eventInfo->where.IntY()); #endif //$$$$$ Get the point back to window coordinates. Can't we just look at the original event? ODPoint xForm = eventInfo->where; { TempODTransform wcTform = facet->AcquireWindowFrameTransform(ev, kODNULL); wcTform->TransformPoint(ev, &xForm); } #if ODDebug && ODDebugCursor PRINT("MouseWithin Window X: %d Y: %d\n",xForm.IntX(),xForm.IntY()); #endif somSelf->AdjustCursor(ev, &xForm); handled = kODTrue; break; case kODEvtMouseLeave: #if ODDebug && ODDebugCursor PRINT("MouseLeave\n"); #endif SetCursor(&(ODQDGlobals.arrow)); handled = kODTrue; break; default: return kODFalse; } return handled; SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextHandleMouseDown(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet, ODPoint* where, ODEventData* event) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","HandleMouseDown"); SOM_TRY GrafPtr curPort; Point thePoint; Point xForm, localPoint; ODShape* clipShape = kODNULL; RgnHandle saveClip, clipRgn; ODBoolean bgClick = (event->what==kODEvtBGMouseDown); ODBoolean result = !bgClick; // default result is false if bg if ( !facet ) { somPrintf("DragText %d: HandleMouseDown: facet is null\n", somSelf->GetID(ev)); return kODFalse; } ODWindow* window = facet->GetWindow(ev); if (!bgClick && !window->IsActive(ev)) SelectWindow(window->GetPlatformWindow(ev)); else { GetPort(&curPort); SetPort(_fDocument->theWindow); thePoint = event->where; GlobalToLocal(&thePoint); xForm = GetAggregateTranslation(ev, facet).AsQDPoint(); localPoint = where->AsQDPoint(); SubPt(xForm, &localPoint); clipShape = facet->AcquireClipShape(ev, kODNULL); clipRgn = clipShape->CopyQDRegion(ev); saveClip = ODNewRgn(); GetClip(saveClip); OffsetRgn(clipRgn, xForm.h, xForm.v); SetClip(clipRgn); #ifdef SHOW_SCROLL_BARS // <eeh> better to put this on the stack, but I can't get it to work ControlActionUPP scrollProcUPP = NewControlActionProc( ScrollProc ) ; ControlHandle theControl; short thePart; thePart = FindControl(thePoint, _fDocument->theWindow, &theControl); if (thePart && !bgClick) { if (theControl == _fDocument->vScroll) { if (thePart == inThumb) { TrackControl(theControl, thePoint, 0L); AdjustDocumentView(_fDocument); } else { TrackControl( theControl, thePoint, scrollProcUPP ) ; } somSelf->AdjustScrollBar(ev); } somSelf->ActivateFrame(ev, facet->GetFrame(ev)); } else #endif if (PtInRgn(thePoint, _fDocument->hiliteRgn)) { if ( !_fDocument->frameIsActive ) TEActivate(_fDocument->theTE); if (!somSelf->DoDragText(ev, event)) { if( !bgClick ) { somSelf->ActivateFrame(ev, facet->GetFrame(ev)); TEClick(thePoint, false, _fDocument->theTE); somSelf->ExpandSelectionAroundLink(ev); } } else { if ( !_fDocument->frameIsActive ) TEDeactivate(_fDocument->theTE); result = kODTrue; // Handled event even if in bg } } else if (somSelf->PtInDestinationLink(ev, &thePoint)) { // If the mouse went down over a destination link, select the entire link // and check for dragging. If TextEdit isn't active, activate it // so the destination link is hilighted. PRINT("Click over destination link\n"); if ( !_fDocument->frameIsActive ) TEActivate(_fDocument->theTE); TESetSelect(_fDstLink.start, _fDstLink.end, _fDocument->theTE); TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); if ( !somSelf->DoDragText(ev, event) ) { if( !bgClick ) somSelf->ActivateFrame(ev, facet->GetFrame(ev)); } else { if ( !_fDocument->frameIsActive ) TEDeactivate(_fDocument->theTE); result = kODTrue; // Handled event even if in bg } } else if (!bgClick && PtInRect(thePoint, &(**(_fDocument->theTE)).viewRect)) { somSelf->ActivateFrame(ev, facet->GetFrame(ev)); TEClick(thePoint, (event->modifiers & shiftKey) != 0, _fDocument->theTE); somSelf->ExpandSelectionAroundLink(ev); } #ifdef SHOW_SCROLL_BARS DisposeRoutineDescriptor( scrollProcUPP ) ; #endif TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); SetClip(saveClip); if (clipShape) clipShape->Release(ev); ODDisposeHandle((Handle)saveClip); ODDisposeHandle((Handle)clipRgn); SetPort(curPort); } return result; SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextPtInDestinationLink(AppleTestDrag_DragText *somSelf, Environment *ev, Point* thePoint) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","PtInDestinationLink"); SOM_TRY ODBoolean result = kODFalse; if ( _fDstLink.link != ((ODLink*) kODNULL) ) { RgnHandle destLinkRgn = ODNewRgn(); THROW_IF_NULL(destLinkRgn); ODSShort startOffset = _fDstLink.start; do { RgnHandle lineRgn = LineBorderFromRange(&startOffset, _fDstLink.end, _fDocument->theTE); if ( lineRgn != kODNULL ) { UnionRgn(lineRgn, destLinkRgn, destLinkRgn); ODDisposeHandle((Handle)lineRgn); } } while (startOffset < _fDstLink.end); result = PtInRgn(*thePoint, destLinkRgn); ODDisposeHandle((Handle)destLinkRgn); } return result; SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } SOM_Scope ODLinkSource* SOMLINK AppleTestDrag_DragTextCreateLink(AppleTestDrag_DragText *somSelf, Environment *ev, ODByteArray* data) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CreateLink"); ODUnused(data); SOM_TRY #if ODDebug ODISOStr isoStr = (ODISOStr) ODNewPtr(data->_length + 1, kDefaultHeapID); if ( data->_length > 0 ) memcpy(isoStr, data->_buffer, data->_length); isoStr[data->_length] = 0; PRINT("DragText: CreateLink: %s, %s\n", isoStr, kDummyLinkSpecData); if ( ODISOStrEqual(isoStr, kDummyLinkSpecData) == kODFalse ) WARN("DragText::CreateLink - LinkSpec data corrupted"); ODDisposePtr(isoStr); #endif TEHandle myTE = _fDocument->theTE; ODULong textSize; if (_fSrcLink.linkSource == (ODLinkSource*) kODNULL) { textSize = _fSrcLink.end-_fSrcLink.start; if (textSize > 0) { _fSrcLink.linkSource = _fDraft->CreateLinkSource(ev, _fPartWrapper); _fSrcLink.change = _fSession->UniqueUpdateID(ev); somSelf->LinkChanged(ev, &_fSrcLink, _fSrcLink.change); // default to automatic } } _fSrcLink.linkSource->Acquire(ev); return _fSrcLink.linkSource; SOM_CATCH_ALL SOM_ENDTRY return kODNULL; } SOM_Scope void SOMLINK AppleTestDrag_DragTextLinkChanged(AppleTestDrag_DragText *somSelf, Environment *ev, AppleTestDrag_DragText_SrceOfLink* srcLink, ODUpdateID updateID) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","LinkChanged"); SOM_TRY #ifdef LINK_TO_TEXT_ONLY TEHandle myTE = _fDocument->theTE; ODULong textSize; CharsHandle text; if (srcLink->linkSource != (ev, (ODLinkSource*) kODNULL)) { ODLinkKey key; TRY if (srcLink->linkSource->Lock(ev, 0, &key)) { srcLink->linkSource->Clear(ev, updateID, key); ODStorageUnit* su = srcLink->linkSource->GetContentStorageUnit(ev, key); if (su->Exists(ev, kODPropContents, (ODValueType) kODNULL, 0) == kODFalse) { su->AddProperty(ev, kODPropContents); } if (su->Exists(ev, kODPropContents, kODAppleTEXT, 0) == kODFalse) { su->AddValue(ev, kODAppleTEXT); } else { ODULong valueSize; su->Focus(ev, kODPropContents, kODPosUndefined, kODAppleTEXT, 0, kODPosUndefined); valueSize = su->GetSize(ev); su->DeleteValue(ev, valueSize); } su->Focus(ev, kODPropContents, kODPosUndefined, kODAppleTEXT, 0, kODPosUndefined); textSize = srcLink->end - srcLink->start; text = (CharsHandle) (*myTE)->hText; ODLockHandle((ODHandle) text); StorageUnitSetValue(su, ev, textSize, (ODValue) ((*text) + srcLink->start)); ODUnlockHandle((ODHandle) text); srcLink->linkSource->ContentUpdated(ev, updateID, key); srcLink->linkSource->Unlock(ev, key); _fDirty = kODTrue; } CATCH(kODErrBrokenLink) PRINT("DragText: ODLinkSource::Lock() returned broken link error\n"); somSelf->RemoveSrcLink(ev); CATCH_ALL PRINT("DragText: ODLinkSource::Lock() returned error\n"); ENDTRY } #else if (srcLink->linkSource != (ev, (ODLinkSource*) kODNULL)) { ODLinkKey key; if (srcLink->linkSource->Lock(ev, 0, &key)) { srcLink->linkSource->Clear(ev, updateID, key); ODStorageUnit* su = srcLink->linkSource->GetContentStorageUnit(ev, key); #ifdef BOGUS_CONTENT_FRAME // Testing: Add a content frame property to the content su if ( su->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0) == kODFalse ) { su->AddProperty(ev, kODPropContentFrame); su->AddValue(ev, kODWeakStorageUnitRef); ODStorageUnit* suPseudoFrame = _fDraft->CreateStorageUnit(ev); ODStorageUnitRef aSURef; su->GetWeakStorageUnitRef(ev, suPseudoFrame->GetID(ev), aSURef); StorageUnitSetValue(su, ev, sizeof(ODStorageUnitRef), aSURef); suPseudoFrame->Release(ev); } #endif TEHandle theTE = _fDocument->theTE; ODSShort selStart = (**(theTE)).selStart; ODSShort selEnd = (**(theTE)).selEnd; // Temporarily change the selection to the link source // don't use TempSelect because of conflict with TSM // TempSelect(srcLink->start, srcLink->end, _fDocument->theTE, _fHasFoci); (**(theTE)).selStart = srcLink->start; (**(theTE)).selEnd = srcLink->end; somSelf->ExternalizeSelection(ev, su, kODCloneToLink); // Restore the selection // don't use TempSelect because of conflict with TSM // TempSelect(selStart, selEnd, _fDocument->theTE, _fHasFoci); (**(theTE)).selStart = selStart; (**(theTE)).selEnd = selEnd; srcLink->linkSource->ContentUpdated(ev, updateID, key); srcLink->linkSource->Unlock(ev, key); } } #endif SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextLinkUpdated(AppleTestDrag_DragText *somSelf, Environment *ev, ODLink* updatedLink, ODUpdateID change) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","LinkUpdated"); ODUnused(change); SOM_TRY if ( updatedLink == _fDstLink.link ) { ODSShort oldSize = _fDstLink.end - _fDstLink.start; ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; #ifdef SHOW_LINK_BORDERS somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif PRINT("DragText: Updating link destination; old size = %d, \n", oldSize); // If the frame is not active, must activate TE before inserting // text or the background hilite will not update correctly. ODFrameFacetIterator* fiter = kODNULL; if ( !_fDocument->frameIsActive ) { fiter = _fDocument->theFrame->CreateFacetIterator(ev); somSelf->ClipThis(ev, fiter->First(ev)); // $$$$$ crc 10/20/94 Not necessary??? TEActivate(_fDocument->theTE); } // Select the existing linked text // Unfortunately, TempSelect doesn't seem to clip effectively // TempSelect(_fDstLink.start, _fDstLink.end, _fDocument->theTE, _fDocument->frameIsActive); TESetSelect(_fDstLink.start, _fDstLink.end, _fDocument->theTE); // Replace the selection with the new link content somSelf->IncorporateContentFromLink(ev); ODSShort newSize = _fDstLink.end - _fDstLink.start; PRINT("DragText: Updating link destination; new size = %d\n", newSize); // Restore the original selection; Doesn't handle overlapping if ( selStart > _fDstLink.start ) { selStart -= (oldSize - newSize); } if ( selEnd > _fDstLink.start ) { selEnd -= (oldSize - newSize); } TESetSelect(selStart, selEnd, _fDocument->theTE); // Undo the TEActivate, if needed. if ( !_fDocument->frameIsActive ) { // $$$$$ crc 10/20/94 Not necessary??? TEDeactivate(_fDocument->theTE); somSelf->ClipToRoot(ev, fiter->First(ev)); } ODDeleteObject(fiter); } else { WARN("Unknown link passed to LinkUpdated()!"); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextIncorporateContentFromLink(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","IncorporateContentFromLink"); SOM_TRY ODLinkKey key; if (_fDstLink.link->Lock(ev, 0, &key)) { TRY ODBoolean successful = kODTrue; ODUpdateID change = _fDstLink.link->GetUpdateID(ev); ODStorageUnit* su = _fDstLink.link->GetContentStorageUnit(ev, key); #ifdef BOGUS_CONTENT_FRAME if ( SUExistsThenFocus(ev, su, kODPropContentFrame, kODWeakStorageUnitRef) ) { ODStorageUnitRef aSURef; StorageUnitGetValue(su, ev, sizeof(ODStorageUnitRef), &aSURef); if ( su->IsValidStorageUnitRef(ev, aSURef) ) PRINT("DragText: Content Frame Property found!\n"); else PRINT("DragText: Content Frame Property missing!\n"); } #endif #ifdef LINK_TO_TEXT_ONLY somSelf->IncorporateTextContent(ev, su, change); #else if ( PasteThisKind (ev, su, kODKindTestDrag, _fDstLink.info.kind) ) { somSelf->IncorporateTestDragContent(ev, su, change, kODCloneFromLink); } else if ( PasteThisKind (ev, su, kODApplestxt, _fDstLink.info.kind) ) { somSelf->IncorporateStyledTextContent(ev, su, change); } else if ( PasteThisKind (ev, su, kODApplestyl, _fDstLink.info.kind) ) { somSelf->IncorporateStyledTextContent(ev, su, change); } else if ( PasteThisKind (ev, su, kODAppleTEXT, _fDstLink.info.kind) ) { somSelf->IncorporateTextContent(ev, su, change); } else { PRINT("DragText %d: Desired kind %s not found in link\n", somSelf->GetID(ev), _fDstLink.info.kind); successful = kODFalse; } #endif if ( successful ) { _fDstLink.info.change = change; _fDstLink.info.changeTime = _fDstLink.link->GetChangeTime(ev); } _fDstLink.link->Unlock(ev, key); CATCH_ALL if( ErrorCode()==kODErrCannotEstablishLink ) { ShowErrorAlert(ev, "\pLink could not be created.", ErrorCode(), _fDocument->theFrame); _fDstLink.link->Unlock(ev, key); somSelf->RemoveDstLink(ev); } else _fDstLink.link->Unlock(ev, key); ENDTRY } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextExpandSelectionAroundLink(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ExpandSelectionAroundLink"); ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; ODBoolean expanded = kODFalse; // Make sure the deletion includes the entire link destination if ( (selStart > _fDstLink.start) && (selStart < _fDstLink.end) ) { selStart = _fDstLink.start; expanded = kODTrue; } if ( (selEnd > _fDstLink.start) && (selEnd < _fDstLink.end) ) { selEnd = _fDstLink.end; expanded = kODTrue; } if ( expanded ) { TESetSelect(selStart, selEnd, _fDocument->theTE); TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); } } SOM_Scope void SOMLINK AppleTestDrag_DragTextCheckDstLinkDeletion(AppleTestDrag_DragText *somSelf, Environment *ev, ODSShort start, ODSShort endOld, ODUpdateID change) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CheckDstLinkDeletion"); SOM_TRY if ( change != _fDstLink.link->GetUpdateID(ev) ) { if ( (start <= _fDstLink.start) && (endOld >= _fDstLink.end) ) { // Destination link has been removed. somSelf->RemoveDstLink(ev); } } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextAbandonSourceLinks(AppleTestDrag_DragText *somSelf, Environment *ev, ODSShort start, ODSShort end) // Abandon any link sources in the range start..end, without clearing the link. { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AbandonSourceLinks"); SOM_TRY // Tests copied from AdjustSrcLinks if ( _fSrcLink.linkSource != (ODLinkSource*) kODNULL ) { if (((start < _fSrcLink.start) && (end >= _fSrcLink.end)) || ((start <= _fSrcLink.start) && (end > _fSrcLink.end)) || ((start == _fSrcLink.start) && (end == _fSrcLink.end))) { // Fall in here if // • The text range start..end included more than the entire link, or // • Exactly the link was deleted // In either case, abandon the link PRINT("DragText: Abandoning source link\n"); _fSrcLink.linkSource->Release(ev); _fSrcLink.linkSource = (ODLinkSource*) kODNULL; _fSrcLink.start = -1; _fSrcLink.end = -1; _fSrcLink.change = kODUnknownUpdate; } } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextAdjustLinks(AppleTestDrag_DragText *somSelf, Environment *ev, ODSShort start, ODSShort endOld, ODSShort endNew, ODUpdateID updateID) // Adjust source and destination links following a change to the text edit record { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AdjustLinks"); SOM_TRY somSelf->AdjustDstLinks(ev, start, endOld, endNew, updateID); somSelf->AdjustSrcLinks(ev, start, endOld, endNew, updateID); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextAdjustDstLinks(AppleTestDrag_DragText *somSelf, Environment *ev, ODSShort start, ODSShort endOld, ODSShort endNew, ODUpdateID change) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AdjustDstLinks"); SOM_TRY // Adjust destination links following a change to the text edit record if ( _fDstLink.link && (endOld > start) ) { // Some content was replaced, so see if the destination link // was deleted somSelf->CheckDstLinkDeletion (ev, start, endOld, change); } if ( _fDstLink.link ) { if ( (start == _fDstLink.start) && (endOld == _fDstLink.end) ) { // Destination link has been updated _fDstLink.end = endNew; } else if ( start >= _fDstLink.end ) { // No change to destination link } else { // Must be entirely before the destination link _fDstLink.start += (endNew - endOld); _fDstLink.end += (endNew - endOld); } } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextAdjustSrcLinks(AppleTestDrag_DragText *somSelf, Environment *ev, ODSShort start, ODSShort endOld, ODSShort endNew, ODUpdateID change) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AdjustSrcLinks"); SOM_TRY // Adjust source link offsets following a change to the text edit record // Text in the range start..endOld was replaced by the range start..endNew. // Note that this routine calls ContentUpdated(); this can cause the LinkUpdated // method of this object to be called, which calls this method. // On entry, _fSrcLink contains old offsets. On exit, _fSrcLink contains new offsets. if ((start >= _fSrcLink.end) && (endOld > _fSrcLink.end)) { // Source link not affected // Note that we don't fall in here if text is inserted immediately after // the link, that is, if start == endOld == _fSrcLink.end return; } if (((start < _fSrcLink.start) && (endOld >= _fSrcLink.end)) || ((start <= _fSrcLink.start) && (endOld > _fSrcLink.end)) || ((endNew == start) && (start == _fSrcLink.start) && (endOld == _fSrcLink.end))) { // Fall in here if // • The text range start..endOld included more than the entire link, or // • Exactly the link was deleted with no replacement // In either case, delete the link somSelf->RemoveSrcLink(ev); return; } if ((endOld <= _fSrcLink.start) && (start < _fSrcLink.start)) { // Changes occurred ahead of the source link, so just move it accordingly // (Treat the case of an insertion point at the beginning of the link as // inserting into the link; handled below). _fSrcLink.start += (endNew - endOld); _fSrcLink.end += (endNew - endOld); return; } if (start == endOld) { // Additions occurred at the insertion point after the last character in // the link _fSrcLink.end += (endNew - endOld); } else if (start < _fSrcLink.start) { // Only that portion of link unaffected remains within the link _fSrcLink.start = start + endNew; _fSrcLink.end += (endNew - endOld); } else if (endOld > _fSrcLink.end) { // Only that portion of link unaffected remains within the link // The replaced text starts in the selection and continues beyond _fSrcLink.end = start; } else { // Replaced text lies entirely within the link, so all new text // is included in the link _fSrcLink.end += (endNew - endOld); } _fSrcLink.change = change; if ( _fSrcLink.linkSource != (ODLinkSource*) kODNULL ) if ( _fSrcLink.linkSource->IsAutoUpdate(ev) ) somSelf->LinkChanged(ev, &_fSrcLink, change); somSelf->RemoveLinkSpec(ev); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextRemoveDstLink(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RemoveDstLink"); SOM_TRY #ifdef SHOW_LINK_BORDERS somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif if (_fDstLink.link != ((ODLink*) kODNULL)) { if ( _fDstLink.info.autoUpdate ) _fDstLink.link->UnregisterDependent(ev, _fPartWrapper); _fDstLink.link->Release(ev); } _fDstLink.link = (ODLink*) kODNULL; _fDstLink.start = -1; _fDstLink.end = -1; _fDstLink.info.kind = (ODType) kODNULL; _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextRemoveSrcLink(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RemoveSrcLink"); SOM_TRY ODLinkSource* linkSource = _fSrcLink.linkSource; #ifdef SHOW_LINK_BORDERS somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif AppleTestDrag_DragText_SrceOfLink tempSrcLink = _fSrcLink; // Null the source link prior to calling ContentUpdated() to prevent // indefinite recursion. _fSrcLink.linkSource = (ODLinkSource*) kODNULL; if ( tempSrcLink.linkSource ) { // Update the link with empty content. // Calling ODLinkSource::Clear() is not sufficient, because an // empty value is not valid; a valid Test Drag value is a reference // to a storage unit, and a zero-length styl record isn't valid. tempSrcLink.start = 0; tempSrcLink.end = 0; TRY // $$$$$ Need to use the change id associated with the operation that // caused the source link to be removed somSelf->LinkChanged(ev, &tempSrcLink, _fSession->UniqueUpdateID(ev)); CATCH_ALL ENDTRY tempSrcLink.linkSource->SetSourcePart(ev, kODNULL); tempSrcLink.linkSource->Release(ev); } somSelf->RemoveLinkSpec(ev); _fSrcLink.start = -1; _fSrcLink.end = -1; _fSrcLink.change = kODUnknownUpdate; SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextRemoveLinkSpec(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RemoveLinkSpec"); SOM_TRY // $$$$$ Really should pass in the correct frame ODFrame* frame = (ODFrame*) _fDisplayFrames->First(); if ( frame != (ODFrame*) kODNULL ) { ODArbitrator* arbitrator = _fSession->GetArbitrator(ev); ODFrame* clipboardFocus = arbitrator->AcquireFocusOwner(ev, _fClipboardFocus); if ( (frame == clipboardFocus) || (arbitrator->RequestFocus(ev, _fClipboardFocus, frame)) ) { // Remove the link spec from the clipboard ODClipboard* clipboard = _fSession->GetClipboard(ev); if ( _fClipboardUpdateID == clipboard->GetUpdateID(ev) ) { TRY ODStorageUnit* clipRootSU = clipboard->GetContentStorageUnit(ev); if ( clipRootSU->Exists(ev, kODPropLinkSpec, (ODValueType) kODNULL, 0) != kODFalse ) { clipRootSU->Focus(ev, kODPropLinkSpec, kODPosUndefined, (ODValueType) kODNULL, 0, kODPosUndefined); clipRootSU->Remove(ev); } CATCH_ALL ENDTRY } } ODReleaseObject(ev, clipboardFocus); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextHandleMouseDownInBorder(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* container, ODFacet* facet, ODPoint* where, ODEventData* event) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","HandleMouseDownInBorder"); ODUnused(container); ODUnused(facet); ODUnused(where); ODUnused(event); SysBeep(2); return kODFalse; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextHandleKeyDown(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* focusFrame, ODEventData* event) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","HandleKeyDown"); SOM_TRY ODBoolean handled = kODFalse; #ifdef SHOW_LINK_BORDERS somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif if (/*!ParentPrtRCR::HandleKeyDown(focusFrame, event) &&*/ focusFrame) { if (event->modifiers & (0xFFFFFFFF & cmdKey)) // was cmd key down? { ODULong mcValue = MenuKey((short)(event->message & charCodeMask)); ODCommandID command = _fMenuBar->GetCommand(ev, HiWord(mcValue),LoWord(mcValue)); handled = somSelf->DoCommand(ev, focusFrame,command); } else if ( focusFrame->GetLinkStatus(ev) == kODInLinkDestination ) { if ( !focusFrame->EditInLink(ev) ) // Put up an alert; WARN("DragText: The destination of a link cannot be edited."); } else { ODSShort delStart; ODSShort delEnd; ODSShort newEnd; char key = (char) (event->message) & charCodeMask; delStart = (**(_fDocument->theTE)).selStart; delEnd = (**(_fDocument->theTE)).selEnd; ODFrameFacetIterator* fiter = focusFrame->CreateFacetIterator(ev); /* $$$$$ */ SetPort(fiter->First(ev)->GetCanvas(ev)->GetQDPort(ev)); somSelf->ClipThis(ev, fiter->First(ev)); if ( key == 8 /* Delete key */ ) { PRINT("Delete key\n"); ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; if ( (selStart == selEnd) && (selStart == _fDstLink.end) ) TESetSelect(_fDstLink.start, _fDstLink.end, _fDocument->theTE); } TEKey(key, _fDocument->theTE); somSelf->AdjustScrollBar(ev); TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); somSelf->ClipToRoot(ev, fiter->First(ev)); handled = kODTrue; ODDeleteObject(fiter); if ((key == kRightArrow) || (key == kLeftArrow) || (key == kUpArrow) || (key == kDownArrow)) { somSelf->ExpandSelectionAroundLink(ev); } else { newEnd = (**(_fDocument->theTE)).selEnd; if ((delEnd > delStart) || (newEnd != delEnd)) { // Some change occurred if ((delEnd == delStart) && (newEnd < delStart)) { // Special case for delete key delStart = newEnd; } ODUpdateID updateID = _fSession->UniqueUpdateID(ev); somSelf->AdjustLinks(ev, delStart, delEnd, newEnd, updateID); focusFrame->ContentUpdated(ev, updateID); } _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); } } } return (handled); SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoCut(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoCut"); SOM_TRY if ( frame->GetLinkStatus(ev) == kODInLinkDestination ) { if ( !frame->EditInLink(ev) ) // Put up an alert; WARN("DragText: The destination of a link cannot be edited."); return kODTrue; } ODFrame* clipboardFocus = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fClipboardFocus); WASSERTM((frame == clipboardFocus), "DragText::DoCut - Clipboard focus not owned"); ODReleaseObject(ev, clipboardFocus); ODClipboard* clipboard = _fSession->GetClipboard(ev); ODStorageUnit* clipBSU = kODNULL; ODSShort delStart = (**(_fDocument->theTE)).selStart; ODSShort delEnd = (**(_fDocument->theTE)).selEnd; ODPtr text; ODHandle style; TRY clipboard->Clear(ev); clipBSU = clipboard->GetContentStorageUnit(ev); somSelf->ExternalizeSelection(ev, clipBSU, kODCloneCut); _fClipboardUpdateID = clipboard->GetUpdateID(ev); CATCH_ALL WARN("Cut to clipboard failed"); ENDTRY text = ODNewPtr(delEnd-delStart, kDefaultHeapID); ODBlockMove((ODPtr)((*(char **)((**(_fDocument->theTE)).hText)) + (**(_fDocument->theTE)).selStart),text,delEnd-delStart); TEDelete(_fDocument->theTE); ODUpdateID updateID = _fSession->UniqueUpdateID(ev); somSelf->AdjustLinks(ev, delStart, delEnd, delStart, updateID); frame->ContentUpdated(ev, updateID); style = (ODHandle)TEGetStyleScrapHandle(_fDocument->theTE); somSelf->PushUndoAction(ev, frame,kODCommandCut,delStart,delEnd,text,style, "\pUndo Cut", "\pRedo Cut"); _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); return kODTrue; SOM_CATCH_ALL SOM_ENDTRY return kODTrue; } SOM_Scope void SOMLINK AppleTestDrag_DragTextUndoRedoCut(AppleTestDrag_DragText *somSelf, Environment *ev, UndoInfo* action, ODUShort selector) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UndoRedoCut"); ODUnused(action); ODUnused(selector); } SOM_Scope void SOMLINK AppleTestDrag_DragTextAddLinkSpecToSU(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* su) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AddLinkSpecToSU"); SOM_TRY #ifdef SUPPORT_TESTDRAG_KIND // Add a link spec to the storage unit if we don't already have a source link // (or the source link is selected exactly), // and as long as the selection does not include a link destination. // Also, don't add a link spec if draft permissions don't allow writing. ODBoolean makeLinkSpec = kODFalse; if (HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev))) { if (_fSrcLink.linkSource == (ODLinkSource*) kODNULL) { if (_fDstLink.link == (ODLink*) kODNULL) { makeLinkSpec = kODTrue; } else { ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; makeLinkSpec = !RangesOverlap(selStart,selEnd,_fDstLink.start,_fDstLink.end); } } else { ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; makeLinkSpec = (selStart==_fSrcLink.start) && (selEnd==_fSrcLink.end); } } if (makeLinkSpec) { ODByteArray data = CreateByteArrayStruct(kDummyLinkSpecData, ODISOStrLength(kDummyLinkSpecData)); ODLinkSpec* ls = _fDraft->CreateLinkSpec(ev, _fPartWrapper, &data); DisposeByteArrayStruct(data); su->AddProperty(ev, kODPropLinkSpec); ls->WriteLinkSpec(ev, su); ODDeleteObject(ls); // Save away the range for the potential link if (_fSrcLink.linkSource == (ODLinkSource*) kODNULL) { _fSrcLink.start = (**(_fDocument->theTE)).selStart; _fSrcLink.end = (**(_fDocument->theTE)).selEnd; } } #endif SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoCopy(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoCopy"); ODUnused(frame); SOM_TRY ODFrame* clipboardFocus = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fClipboardFocus); WASSERTM((frame == clipboardFocus), "DragText::DoCopy - Clipboard focus not owned"); ODReleaseObject(ev, clipboardFocus); ODClipboard* clipboard = _fSession->GetClipboard(ev); TRY ODStorageUnit* clipBSU = kODNULL; clipboard->Clear(ev); clipBSU = clipboard->GetContentStorageUnit(ev); somSelf->ExternalizeSelection(ev, clipBSU, kODCloneCopy); _fClipboardUpdateID = clipboard->GetUpdateID(ev); somSelf->AddLinkSpecToSU(ev, clipBSU); #ifdef TRYOUT_PROMISE char buffer[] = "abcd"; clipBSU->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosAll); StorageUnitSetPromiseValue(clipBSU, ev, "SomePromiseValue", 0, 4, buffer, _fPartWrapper); #endif CATCH_ALL WARN("Copy to clipboard failed"); ENDTRY return kODTrue; SOM_CATCH_ALL SOM_ENDTRY return kODTrue; } SOM_Scope void SOMLINK AppleTestDrag_DragTextIncorporateTestDragContent(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* su, ODUpdateID change, ODCloneKind cloneKind) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","IncorporateTestDragContent"); SOM_TRY ODSShort delStart = (**(_fDocument->theTE)).selStart; ODSShort delEnd = (**(_fDocument->theTE)).selEnd; ODSShort newEnd; ODValue text = kODNULL; ODULong size = 0; ODULong stsize = 0; StScrpHandle style = kODNULL; ODStorageUnit* testDragSU = kODNULL; ODStorageUnitRef aSURef; ODDraft* fromDraft = su->GetDraft(ev); ODID newLinkID = kODNULLID; ODSShort newLinkStart; ODSShort newLinkEnd; ODLinkInfo newLinkInfo; ODID newLinkSourceID = kODNULLID; ODSShort newLinkSourceStart; ODSShort newLinkSourceEnd; ODUpdateID newLinkSourceChange; ODDraftKey draftKey = fromDraft->BeginClone(ev, _fDraft, (ODFrame*) _fDisplayFrames->First(), cloneKind); TRY su->Focus(ev, kODPropContents, kODPosUndefined, kODKindTestDrag, (ODValueIndex)0, kODPosUndefined); StorageUnitGetValue(su, ev, sizeof(ODStorageUnitRef),&aSURef); testDragSU = fromDraft->AcquireStorageUnit(ev, su->GetIDFromStorageUnitRef(ev, aSURef)); testDragSU->Focus(ev, kDragTextPropText, kODPosUndefined, 0, 1, kODPosFirstSib); size = testDragSU->GetSize(ev); text = (ODValue) ODNewPtr(size, kDefaultHeapID); testDragSU->SetOffset(ev, 0); StorageUnitGetValue(testDragSU, ev, size, text); testDragSU->Focus(ev, kDragTextPropStyl, kODPosUndefined, kODApplestyl, (ODValueIndex)0, kODPosUndefined); stsize = testDragSU->GetSize(ev); style = (StScrpHandle)ODNewHandle(stsize); ODLockHandle((ODHandle) style); testDragSU->SetOffset(ev, 0); StorageUnitGetValue(testDragSU, ev, stsize,(ODValue)(*style)); ODUnlockHandle((ODHandle) style); TEDelete(_fDocument->theTE); TEStyleInsert((void*)text, size, style, _fDocument->theTE); if ( _fSrcLink.linkSource == (ODLinkSource*) kODNULL ) { if ( testDragSU->Exists(ev, kDragTextPropSourceLink, kDragTextValue, kODPosAll) ) { testDragSU->Focus(ev, kDragTextPropSourceLink, kODPosUndefined, kDragTextValue, (ODValueIndex)0, kODPosUndefined); if ( testDragSU->GetSize(ev) > 0 ) { StorageUnitGetValue(testDragSU, ev, sizeof(ODStorageUnitRef), &aSURef); if ( testDragSU->IsValidStorageUnitRef(ev, aSURef) ) { newLinkSourceID = fromDraft->Clone(ev, draftKey, testDragSU->GetIDFromStorageUnitRef(ev, aSURef), 0, 0); StorageUnitGetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &newLinkSourceStart); StorageUnitGetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &newLinkSourceEnd); StorageUnitGetValue(testDragSU, ev, sizeof(ODULong), (ODValue) &newLinkSourceChange); } } } } if ( _fDstLink.link == (ODLink*) kODNULL ) { if ( testDragSU->Exists(ev, kDragTextPropDestLink, kDragTextValue, kODPosAll) ) { testDragSU->Focus(ev, kDragTextPropDestLink, kODPosUndefined, kDragTextValue, (ODValueIndex)0, kODPosUndefined); if ( testDragSU->GetSize(ev) > 0 ) { StorageUnitGetValue(testDragSU, ev, sizeof(ODStorageUnitRef), &aSURef); if ( testDragSU->IsValidStorageUnitRef(ev, aSURef) ) { newLinkID = fromDraft->Clone(ev, draftKey, testDragSU->GetIDFromStorageUnitRef(ev, aSURef), 0, 0); StorageUnitGetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &newLinkStart); StorageUnitGetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &newLinkEnd); StorageUnitGetValue(testDragSU, ev, sizeof(ODLinkInfo), (ODValue) &newLinkInfo); ODType kind = (ODType) ODNewPtr((ODULong) newLinkInfo.kind, kDefaultHeapID); StorageUnitGetValue(testDragSU, ev, (ODULong) newLinkInfo.kind, (ODValue) kind); newLinkInfo.kind = kind; } } } } testDragSU->Release(ev); CATCH_ALL ODReleaseObject(ev, testDragSU); fromDraft->AbortClone(ev, draftKey); RERAISE; ENDTRY fromDraft->EndClone(ev, draftKey); newEnd = (**(_fDocument->theTE)).selEnd; somSelf->AdjustLinks(ev, delStart, delEnd, newEnd, change); if ( _fSrcLink.linkSource == (ODLinkSource*) kODNULL ) { if ( _fDraft->IsValidID(ev, newLinkSourceID) ) { TRY _fSrcLink.linkSource = _fDraft->AcquireLinkSource(ev, newLinkSourceID); _fSrcLink.start = newLinkSourceStart; _fSrcLink.end = newLinkSourceEnd; _fSrcLink.change = newLinkSourceChange; _fSrcLink.start += delStart; _fSrcLink.end += delStart; // Change the link source to reference this part's storage unit _fSrcLink.linkSource->SetSourcePart(ev, somSelf->GetStorageUnit(ev)); // Now notify destinations; necessary if this source link was cut // but some destinations were not. // 12.22.94 crc: I don't remember why this is necessary. // For now I'll assume it is only necessary for automatic links. if ( _fSrcLink.change != _fSrcLink.linkSource->GetUpdateID(ev) ) if ( _fSrcLink.linkSource->IsAutoUpdate(ev) ) somSelf->LinkChanged(ev, &_fSrcLink, _fSrcLink.change); CATCH_ALL _fSrcLink.linkSource = (ODLinkSource*) kODNULL; _fSrcLink.start = -1; _fSrcLink.end = -1; _fSrcLink.change = kODUnknownUpdate; ENDTRY } } if ( _fDstLink.link == (ODLink*) kODNULL ) { if ( _fDraft->IsValidID(ev, newLinkID) ) { TRY _fDstLink.link = _fDraft->AcquireLink(ev, newLinkID, kODNULL); _fDstLink.start = newLinkStart; _fDstLink.end = newLinkEnd; _fDstLink.start += delStart; _fDstLink.end += delStart; ODDisposePtr(_fDstLink.info.kind); _fDstLink.info = newLinkInfo; // Register as a dependent of the link if updates are automatic if ( _fDstLink.info.autoUpdate ) _fDstLink.link->RegisterDependent(ev, _fPartWrapper, _fDstLink.info.change); CATCH_ALL _fDstLink.link = (ODLink*) kODNULL; _fDstLink.start = -1; _fDstLink.end = -1; ODDisposePtr(newLinkInfo.kind); ENDTRY } } _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); SOM_CATCH_ALL PRINT("IncorporateTestDragContent caught exception\n"); SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextIncorporateStyledTextContent(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* su, ODUpdateID change) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","IncorporateStyledTextContent"); SOM_TRY ODSShort delStart = (**(_fDocument->theTE)).selStart; ODSShort delEnd = (**(_fDocument->theTE)).selEnd; ODSShort newEnd; ODValue value = kODNULL; ODULong size = 0; ODULong stsize = 0; Handle textHandle = kODNULL; StScrpHandle styleHandle = kODNULL; // Look first for a styled text property; only use 'styl' + 'TEXT' if not found if (su->Exists(ev, kODPropContents, kODApplestxt, 0) ) { su->Focus(ev, kODPropContents, kODPosUndefined, kODApplestxt, (ODValueIndex)0, kODPosUndefined); ReadStyledText(ev, su, &textHandle, &styleHandle); size = GetHandleSize(textHandle); stsize = GetHandleSize((Handle) styleHandle); } else { su->Focus(ev, kODPropContents, kODPosUndefined, kODAppleTEXT, (ODValueIndex)0, kODPosUndefined); size = su->GetSize(ev); textHandle = (Handle) ODNewHandle(size); value = ODLockHandle((ODHandle) textHandle); su->SetOffset(ev, 0); StorageUnitGetValue(su, ev, size, value); ODUnlockHandle((ODHandle) textHandle); su->Focus(ev, kODPropContents, kODPosUndefined, kODApplestyl, (ODValueIndex)0, kODPosUndefined); stsize = su->GetSize(ev); styleHandle = (StScrpHandle) ODNewHandle(stsize); value = ODLockHandle((ODHandle) styleHandle); su->SetOffset(ev, 0); StorageUnitGetValue(su, ev, stsize, value); ODUnlockHandle((ODHandle) styleHandle); // PRINT("Size of 'styl' handle is %d\n", stsize); // PRINT("First short of 'styl' resource is %d\n", *((short*)(*style))); // PRINT("Computed length of 'styl' resource is %d\n", sizeof(short)+(*((short*)(*style)))*sizeof(ScrpSTElement)); } TEDelete(_fDocument->theTE); value = ODLockHandle((ODHandle) textHandle); if ( stsize > 0 ) TEStyleInsert(value, size, styleHandle, _fDocument->theTE); else TEInsert(value, size, _fDocument->theTE); ODUnlockHandle((ODHandle) textHandle); ODDisposeHandle((Handle) textHandle); ODDisposeHandle((Handle) styleHandle); newEnd = (**(_fDocument->theTE)).selEnd; somSelf->AdjustLinks(ev, delStart, delEnd, newEnd, change); _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextIncorporateTextContent(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* su, ODUpdateID change) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","IncorporateTextContent"); ODSShort delStart = (**(_fDocument->theTE)).selStart; ODSShort delEnd = (**(_fDocument->theTE)).selEnd; ODSShort newEnd; ODULong size; SOM_TRY //#ifdef SHOW_LINK_BORDERS // somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); //#endif // Determine how much text will be pasted su->Focus(ev, kODPropContents, kODPosUndefined, kODAppleTEXT, (ODValueIndex)0, kODPosUndefined); size = su->GetSize(ev); // Insist that this part contains fewer than 20K of text ODULong newSize = (**(_fDocument->theTE)).teLength - (delEnd-delStart) + size; if ( newSize > kMaxTextSize ) THROW(kDragTextErrTooMuchText); // Delete the current selection TEDelete(_fDocument->theTE); if ( size > 0 ) { ODValue text = kODNULL; text = (ODValue) ODNewPtr(size, kDefaultHeapID); su->SetOffset(ev, 0); StorageUnitGetValue(su, ev, size, text); TEInsert((void*)text, size, _fDocument->theTE); ODDisposePtr((ODPtr) text); } newEnd = (**(_fDocument->theTE)).selEnd; somSelf->AdjustLinks(ev, delStart, delEnd, newEnd, change); _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope ODStorageUnit* AppleTestDrag_DragTextTranslateContentKind( AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* contentSU, ODType desiredKind, ODType translateKind) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","TranslateContentKind"); ODStorageUnit* newSU = kODNULL; ODStorageUnitView* fromView = kODNULL; ODStorageUnitView* toView = kODNULL; ODByteArray dataBA; SOM_TRY ODTranslation* translation = contentSU->GetSession(ev)->GetTranslation(ev); // For now, translate into a new storage unit in this draft newSU = _fDraft->CreateStorageUnit(ev); ODVolatile(fromView); ODVolatile(toView); ODVolatile(newSU); TRY contentSU->Focus(ev, kODPropContents, kODPosUndefined, (ODValueType) translateKind, 0, kODPosUndefined); fromView = contentSU->CreateView(ev); // set from view to the original value SUForceFocus(ev, newSU, kODPropContents, desiredKind); toView = newSU->CreateView(ev); // set to view to the this new value ODTranslateResult transResult = translation->TranslateView(ev, fromView, toView); // do the actual translation if ( transResult != kODCanTranslate ) THROW(kDragTextErrCannotTranslate); if ( IsKind(desiredKind, kODApplestyl) ) { if ( SUExistsThenFocus(ev, contentSU, kODPropContents, kODAppleTEXT) ) { ODULong size = contentSU->GetSize(ev); contentSU->GetValue(ev, size, &dataBA); SUForceFocus(ev, newSU, kODPropContents, kODAppleTEXT); newSU->SetValue(ev, &dataBA); ODDisposePtr(dataBA._buffer); } } CATCH_ALL ODDeleteObject(fromView); ODDeleteObject(toView); ODReleaseObject(ev, newSU); // $$$$$ Should remove from draft RERAISE; ENDTRY ODDeleteObject(fromView); ODDeleteObject(toView); return newSU; SOM_CATCH_ALL SOM_ENDTRY return kODNULL; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoPaste(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODType desiredKind, ODType translateKind) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoPaste"); ODUnused(frame); SOM_TRY if ( frame->GetLinkStatus(ev) == kODInLinkDestination ) { if ( !frame->EditInLink(ev) ) // Put up an alert; WARN("DragText: The destination of a link cannot be edited."); return kODTrue; } ODFrame* clipboardFocus = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fClipboardFocus); WASSERTM((frame == clipboardFocus), "DragText::DoPaste - Clipboard focus not owned"); ODReleaseObject(ev, clipboardFocus); ODClipboard* clipboard = _fSession->GetClipboard(ev); TRY ODStorageUnit* clipBSU = clipboard->GetContentStorageUnit(ev); ODStorageUnit* contentSU; ODUpdateID updateID = _fSession->UniqueUpdateID(ev); if ( translateKind == kODNULL ) contentSU = clipBSU; else // Need to translate prior to incorporating the content contentSU = somSelf->TranslateContentKind(ev, clipBSU, desiredKind, translateKind); #ifdef SUPPORT_TESTDRAG_KIND if ( PasteThisKind (ev, contentSU, kODKindTestDrag, desiredKind) ) { somSelf->OpenWhitespace(ev, contentSU, kODKindTestDrag); somSelf->IncorporateTestDragContent(ev, contentSU, updateID, kODClonePaste); frame->ContentUpdated(ev, updateID); } else #endif if ( PasteThisKind (ev, contentSU, kODApplestxt, desiredKind) || PasteThisKind (ev, contentSU, kODApplestyl, desiredKind) ) { somSelf->OpenWhitespace(ev, contentSU, kODAppleTEXT); somSelf->IncorporateStyledTextContent(ev, contentSU, updateID); frame->ContentUpdated(ev, updateID); } else if ( PasteThisKind (ev, contentSU, kODAppleTEXT, desiredKind) ) { somSelf->OpenWhitespace(ev, contentSU, kODAppleTEXT); somSelf->IncorporateTextContent(ev, contentSU, updateID); frame->ContentUpdated(ev, updateID); } if ( translateKind != kODNULL ) { // Focus to the contents property and remove it contentSU->Focus(ev, kODPropContents, kODPosUndefined, (ODValueType) kODNULL, 0, kODPosUndefined); contentSU->Remove(ev); ODReleaseObject(ev, contentSU); // $$$$$ Should remove storage unit } CATCH_ALL if ( ErrorCode() == kDragTextErrTooMuchText ) ShowInfoAlert(ev, "\pToo much text to paste here.", frame); else ShowErrorAlert(ev, "\pError during Paste.", ErrorCode(), frame); ENDTRY return kODTrue; SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } SOM_Scope void SOMLINK AppleTestDrag_DragTextUndoRedoPaste(AppleTestDrag_DragText *somSelf, Environment *ev, UndoInfo* action, ODUShort selector) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UndoRedoPaste"); ODUnused(action); ODUnused(selector); } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoPasteAs(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoPasteAs"); SOM_TRY ODPasteAsResult pasteAsRslt; pasteAsRslt.selectedKind = kODNULL; pasteAsRslt.translateKind = kODNULL; pasteAsRslt.editor = kODNULL; TempODPasteAsResult tempResult = &pasteAsRslt; // DMc: ensure deletion of selectedKind, translateKind, editor ODBoolean result = kODTrue; if ( frame->GetLinkStatus(ev) == kODInLinkDestination ) { if ( !frame->EditInLink(ev) ) // Put up an alert; WARN("DragText: The destination of a link cannot be edited."); return kODTrue; } ODFrame* clipboardFocus = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fClipboardFocus); WASSERTM((frame == clipboardFocus), "DragText::DoPasteAs - Clipboard focus not owned"); ODReleaseObject(ev, clipboardFocus); ODClipboard* clipboard = _fSession->GetClipboard(ev); ODFrameFacetIterator* facets = (ODFrameFacetIterator*) kODNULL; #ifdef SHOW_CLIPBOARD_PASTE_AS_DIALOG TRY ODStorageUnit* clipContentSU = clipboard->GetContentStorageUnit(ev); facets = frame->CreateFacetIterator(ev); if ( clipboard->ShowPasteAsDialog(ev, somSelf->CanPasteLink(ev, clipContentSU, (clipboard->GetUpdateID(ev) == _fClipboardUpdateID), (**(_fDocument->theTE)).selStart, (**(_fDocument->theTE)).selEnd), kODPasteAsMergeOnly, facets->First(ev), _fSession->Tokenize(ev, kODViewAsFrame), &pasteAsRslt) ) { if ( pasteAsRslt.pasteLinkSetting != kODFalse ) { // $$$$$ Cannot yet paste a link if translation is required if ( pasteAsRslt.translateKind != kODNULL ) THROW(kDragTextErrTranslateLinkError); result = somSelf->DoPasteLink(ev, frame, pasteAsRslt.selectedKind); } else result = somSelf->DoPaste(ev, frame, pasteAsRslt.selectedKind, pasteAsRslt.translateKind); } CATCH_ALL PRINT("DoPasteAs caught error %d\n", ErrorCode()); ENDTRY ODDeleteObject(facets); #else result = somSelf->DoPasteLink(ev, frame, kODAppleTEXT); #endif return result; SOM_CATCH_ALL SOM_ENDTRY return kODTrue; } SOM_Scope void SOMLINK AppleTestDrag_DragTextPasteLinkFromSU(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODType desiredKind, ODStorageUnit* su) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","PasteLinkFromSU"); SOM_TRY if (su->Exists(ev, kODPropLinkSpec, (ODValueType) kODNULL, 0) != kODFalse) { ODLinkSpec* ls = _fDraft->CreateLinkSpec(ev, kODNULL, kODNULL); su->Focus(ev, kODPropLinkSpec, kODPosUndefined, (ODValueType) kODNULL, 0, kODPosUndefined); ls->ReadLinkSpec(ev, su); TRY _fDstLink.link = _fDraft->AcquireLink(ev, (ODStorageUnitID) kODNULL, ls); if (_fDstLink.link != (ODLink*) kODNULL) { ODSShort delStart = (**(_fDocument->theTE)).selStart; ODSShort delEnd = (**(_fDocument->theTE)).selEnd; // Delete the existing text and wait for LinkUpdated() to be // called to get the text TEDelete(_fDocument->theTE); _fDstLink.info.change = _fDstLink.link->GetUpdateID(ev); GetDateTime((ODTime*) &_fDstLink.info.creationTime); _fDstLink.info.changeTime = _fDstLink.info.creationTime; _fDstLink.info.kind = (ODType) ODISOStrFromCStr(desiredKind); _fDstLink.info.autoUpdate = kODTrue; // Adjust other links due to this change // Special cased for source links only for now // Assume no overlapping links or recursion problems somSelf->AdjustSrcLinks(ev, delStart, delEnd, delStart, _fDstLink.info.change); _fDstLink.start = delStart; _fDstLink.end = delStart; // Now register as a dependent of the link // Specify kODUnknownUpdate to force getting the text. // By default the destination is automatically updated. _fDstLink.link->RegisterDependent(ev, _fPartWrapper, kODUnknownUpdate); // Put the insertion point after the text TESetSelect(_fDstLink.end, _fDstLink.end, _fDocument->theTE); frame->ContentUpdated(ev, _fDstLink.info.change); _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); } CATCH_ALL if( ErrorCode()==kODErrDocNotSaved ) WARN("Source document not saved!"); ENDTRY ODDeleteObject(ls); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoPasteLink(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODType desiredKind) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoPasteLink"); ODUnused(frame); SOM_TRY ODFrame* clipboardFocus = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fClipboardFocus); WASSERTM((frame == clipboardFocus), "DragText::DoPasteLink - Clipboard focus not owned"); ODReleaseObject(ev, clipboardFocus); ODClipboard* clipboard = _fSession->GetClipboard(ev); TRY ODStorageUnit* clipBSU = clipboard->GetContentStorageUnit(ev); somSelf->PasteLinkFromSU(ev, frame, desiredKind, clipBSU); CATCH_ALL ENDTRY return kODTrue; SOM_CATCH_ALL SOM_ENDTRY return kODTrue; } SOM_Scope void SOMLINK AppleTestDrag_DragTextUndoRedoPasteLink(AppleTestDrag_DragText *somSelf, Environment *ev, UndoInfo* action, ODUShort selector) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UndoRedoPasteLink"); ODUnused(action); ODUnused(selector); } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextSelectionInLinkSource(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","SelectionInLinkSource"); ODBoolean inSourceLink = kODFalse; ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; if (_fSrcLink.linkSource == ((ODLinkSource*) kODNULL)) inSourceLink = kODFalse; else if ((selStart >= _fSrcLink.start) && (selStart < _fSrcLink.end)) inSourceLink = kODTrue; else if ((selEnd > _fSrcLink.start) && (selEnd <= _fSrcLink.end)) inSourceLink = kODTrue; else if ((selStart <= _fSrcLink.start) && (selEnd >= _fSrcLink.end)) inSourceLink = kODTrue; else inSourceLink = kODFalse; return inSourceLink; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextSelectionInLinkDestination(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","SelectionInLinkDestination"); ODBoolean inDestinationLink = kODFalse; ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; if ((selStart >= _fDstLink.start) && (selStart < _fDstLink.end)) inDestinationLink = kODTrue; else if ((selEnd > _fDstLink.start) && (selEnd <= _fDstLink.end)) inDestinationLink = kODTrue; else if ((selStart <= _fDstLink.start) && (selEnd >= _fDstLink.end)) inDestinationLink = kODTrue; return inDestinationLink; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoLinkInfo(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoLinkInfo"); // For now, suppress any errors returned by ShowInfo. The ShowInfo methods may // return a broken link error; rather than handling them by alerting the user and // removing the link object, just do nothing. TRY ODBoolean result = kODTrue; ODLinkInfoResult infoResult; ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev); if (somSelf->SelectionInLinkSource(ev)) { if ( _fSrcLink.linkSource->ShowLinkSourceInfo(ev, facets->First(ev), _fSrcLink.change, kODTrue, &infoResult) ) { switch (infoResult.action) { case kODLinkInfoBreakLink: #ifdef SHOW_LINK_BORDERS somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif _fSrcLink.linkSource->SetSourcePart(ev, (ODStorageUnit*) kODNULL); _fSrcLink.linkSource->Release(ev); _fSrcLink.linkSource = (ODLinkSource*) kODNULL; _fSrcLink.start = -1; _fSrcLink.end = -1; _fSrcLink.change = kODUnknownUpdate; _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); break; case kODLinkInfoUpdateNow: somSelf->LinkChanged(ev, &_fSrcLink, _fSrcLink.change); break; case kODLinkInfoOk: if ( infoResult.autoUpdate != _fSrcLink.linkSource->IsAutoUpdate(ev) ) { _fSrcLink.linkSource->SetAutoUpdate(ev, infoResult.autoUpdate); if ( infoResult.autoUpdate ) if ( _fSrcLink.change != _fSrcLink.linkSource->GetUpdateID(ev) ) { // Changed from manual to automatic updates, and the link // is out of date; update it now somSelf->LinkChanged(ev, &_fSrcLink, _fSrcLink.change); } } break; default: break; } } } else if (somSelf->SelectionInLinkDestination(ev)) { if ( _fDstLink.link->ShowLinkDestinationInfo(ev, facets->First(ev), &_fDstLink.info, kODTrue, &infoResult) ) { switch (infoResult.action) { case kODLinkInfoFindSource: TRY PRINT("DragText %d: Calling ShowSourceContent\n", somSelf->GetID(ev)); _fDstLink.link->ShowSourceContent(ev); PRINT("DragText %d: Returned from ShowSourceContent\n", somSelf->GetID(ev)); CATCH_ALL PRINT("DragText %d: Error %d returned by ODLink::ShowSourceContent\n", somSelf->GetID(ev), ErrorCode()); ShowErrorAlert(ev, "\pCannot show link source", ErrorCode(), frame); ENDTRY; break; case kODLinkInfoBreakLink: somSelf->RemoveDstLink(ev); break; case kODLinkInfoUpdateNow: somSelf->LinkUpdated(ev, _fDstLink.link, _fDstLink.link->GetUpdateID(ev)); break; case kODLinkInfoOk: if ( infoResult.autoUpdate != _fDstLink.info.autoUpdate ) { _fDstLink.info.autoUpdate = infoResult.autoUpdate; // Real parts must be careful of multiple destinations of the same link! if ( infoResult.autoUpdate ) _fDstLink.link->RegisterDependent(ev, _fPartWrapper, _fDstLink.info.change); else _fDstLink.link->UnregisterDependent(ev, _fPartWrapper); } break; default: break; } } #ifdef SHOW_LINK_BORDERS somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif } ODDeleteObject(facets); return kODTrue; // Always handle the event CATCH_ALL ENDTRY return kODFalse; } SOM_Scope void SOMLINK AppleTestDrag_DragTextRevealLink(AppleTestDrag_DragText *somSelf, Environment *ev, ODLinkSource* linkSource) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RevealLink"); SOM_TRY if ( _fSrcLink.linkSource != linkSource ) THROW(kDragTextErrInvalidLink); ODFrame* frame = (ODFrame*) _fDisplayFrames->First(); if ( frame != (ODFrame*) kODNULL ) { ProcessSerialNumber psn; GetCurrentProcess(&psn); SetFrontProcess(&psn); #ifdef SHOW_LINK_BORDERS somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif ODFrame* containingFrame = frame->AcquireContainingFrame(ev); if ( containingFrame != (ODFrame*) kODNULL ) { ODPart* part = containingFrame->AcquirePart(ev); // Sample parts currently THROW so catch and ignore TRY if ( part ) part->RevealFrame(ev, frame, (ODShape*) kODNULL); CATCH_ALL ENDTRY ODReleaseObject(ev, part); containingFrame->Release(ev); } somSelf->ActivateFrame(ev, frame); if (_fHasFoci) { TESetSelect(_fSrcLink.start, _fSrcLink.end, _fDocument->theTE); } } else { // Otherwise open a new window } SOM_CATCH_ALL PRINT("DragText %d: RevealLink :Error %d caught\n", somSelf->GetID(ev), ErrorCode()); SOM_ENDTRY } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextShowAboutBox(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ShowAboutBox"); SOM_TRY ODTypeToken modalFocus = _fSession->Tokenize(ev, kODModalFocus); ODFrame* currentOwner = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, modalFocus); if (_fSession->GetArbitrator(ev)->RequestFocus(ev, modalFocus, frame)) { short itemHit; ParamText("\pDragText Part…",0,0,0); SetCursor(&ODQDGlobals.arrow); ModalFilterUPP modalFilter = NewModalFilterProc(DragTextDialogFilter); ODSLong savedRefNum; BeginUsingLibraryResources(savedRefNum); DialogPtr aboutDialog = GetNewDialog(kDragText_AboutBoxID ,0, (WindowPtr) -1L); EndUsingLibraryResources(savedRefNum); if (aboutDialog) { _fSession->GetWindowState(ev)->DeactivateFrontWindows(ev); ((WindowPeek)aboutDialog)->refCon = (long) _fSession; ShowWindow(aboutDialog); ModalDialog(modalFilter, &itemHit); DisposeDialog(aboutDialog); _fSession->GetWindowState(ev)->ActivateFrontWindows(ev); } DisposeRoutineDescriptor(modalFilter); _fSession->GetArbitrator(ev)->TransferFocus(ev, modalFocus, frame, currentOwner); } else SysBeep(2); ODReleaseObject(ev, currentOwner); return kODTrue; SOM_CATCH_ALL SOM_ENDTRY return kODTrue; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoClear(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoClear"); SOM_TRY ODSShort delStart = (**(_fDocument->theTE)).selStart; ODSShort delEnd = (**(_fDocument->theTE)).selEnd; if (delEnd > delStart) { if ( frame->GetLinkStatus(ev) == kODInLinkDestination ) { if ( !frame->EditInLink(ev) ) // Put up an alert; WARN("DragText: The destination of a link cannot be edited."); return kODTrue; } TEDelete(_fDocument->theTE); ODUpdateID updateID = _fSession->UniqueUpdateID(ev); somSelf->AdjustLinks(ev, delStart, delEnd, delStart, updateID); frame->ContentUpdated(ev, updateID); _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); } return kODTrue; SOM_CATCH_ALL SOM_ENDTRY return kODTrue; } SOM_Scope void SOMLINK AppleTestDrag_DragTextUndoRedoClear(AppleTestDrag_DragText *somSelf, Environment *ev, UndoInfo* action, ODUShort selector) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UndoRedoClear"); ODUnused(action); ODUnused(selector); } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoSelectAll(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoSelectAll"); ODUnused(frame); TESetSelect(0,32767,_fDocument->theTE); return kODTrue; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoSampleOne(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoSampleOne"); SOM_TRY char* defOne = "As I sailed into Shadow, a white bird of my desire came and sat upon my right shoulder, and I wrote a note and tied it to its leg and sent in on its way."; TESetText(defOne, strlen(defOne), _fDocument->theTE); somSelf->RemoveSrcLink(ev); somSelf->RemoveDstLink(ev); ODFrameFacetIterator* facet = frame->CreateFacetIterator(ev); facet->First(ev)->Invalidate(ev, kODNULL, kODNULL); ODDeleteObject(facet); _fFrameShapeChanged = true; _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); return kODTrue; SOM_CATCH_ALL SOM_ENDTRY return kODTrue; } SOM_Scope void SOMLINK AppleTestDrag_DragTextUndoRedoSampleOne(AppleTestDrag_DragText *somSelf, Environment *ev, UndoInfo* action, ODUShort selector) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UndoRedoSampleOne"); ODUnused(action); ODUnused(selector); } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoSampleTwo(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoSampleTwo"); SOM_TRY char* defTwo = "A black bird of my desire came and sat on my left shoulder, and I wrote a note and tied it to its leg and sent it off into the west."; TESetText(defTwo, strlen(defTwo), _fDocument->theTE); somSelf->RemoveSrcLink(ev); somSelf->RemoveDstLink(ev); ODFrameFacetIterator* facet = frame->CreateFacetIterator(ev); facet->First(ev)->Invalidate(ev, kODNULL, kODNULL); ODDeleteObject(facet); _fFrameShapeChanged = true; _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); return kODTrue; SOM_CATCH_ALL SOM_ENDTRY return kODTrue; } SOM_Scope void SOMLINK AppleTestDrag_DragTextUndoRedoSampleTwo(AppleTestDrag_DragText *somSelf, Environment *ev, UndoInfo* action, ODUShort selector) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UndoRedoSampleTwo"); ODUnused(action); ODUnused(selector); } SOM_Scope void SOMLINK AppleTestDrag_DragTextUndoRedoTyping(AppleTestDrag_DragText *somSelf, Environment *ev, UndoInfo* action, ODUShort selector) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UndoRedoTyping"); ODUnused(action); ODUnused(selector); } SOM_Scope void SOMLINK AppleTestDrag_DragTextUndoRedoStyling(AppleTestDrag_DragText *somSelf, Environment *ev, UndoInfo* action, ODUShort selector) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UndoRedoStyling"); ODUnused(action); ODUnused(selector); } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextDoCommand(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODCommandID command) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoCommand"); SOM_TRY ODBoolean handled = kODFalse; short menu = 0; short item = 0; #ifdef SHOW_LINK_BORDERS // Don't turn off link borders if the command is GetLinkInfo, so the user can // still see the link. if ( command != kODCommandGetPartInfo ) somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif if (!_fMenuBar->IsCommandSynthetic(ev, command)) { switch (command) { case kODCommandAbout: handled = somSelf->ShowAboutBox(ev, frame); break; case kODCommandCut: handled = somSelf->DoCut(ev, frame); break; case kODCommandCopy: handled = somSelf->DoCopy(ev, frame); break; case kODCommandPaste: handled = somSelf->DoPaste(ev, frame, kODNULL, kODNULL); break; case kODCommandPasteAs: handled = somSelf->DoPasteAs(ev, frame); break; case kODCommandClear: handled = somSelf->DoClear(ev, frame); break; case kODCommandSelectAll: handled = somSelf->DoSelectAll(ev, frame); break; case kODCommandGetPartInfo: handled = somSelf->DoLinkInfo(ev, frame); break; case cDTSampleOne: handled = somSelf->DoSampleOne(ev, frame); break; case cDTSampleTwo: handled = somSelf->DoSampleTwo(ev, frame); break; default: break; } } else { _fMenuBar->GetMenuAndItem(ev, command, &menu, &item); switch (menu) { case 141: somSelf->HandleFontMenu(ev, item); handled = kODTrue; break; case 142: somSelf->HandleSizeMenu(ev, item); handled = kODTrue; break; default: break; } } HiliteMenu(0); return (handled); SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextHandleMenuEvent(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODEventData* event) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","HandleMenuEvent"); SOM_TRY long menuResult = event->message; short menu = HiWord(menuResult); short item = LoWord(menuResult); ODCommandID command = _fMenuBar->GetCommand(ev, menu, item); ODBoolean handled = somSelf->DoCommand(ev, frame, command); return (handled); SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } //------------------------------------------------------------------------- // From Undo Protocol //------------------------------------------------------------------------- SOM_Scope void SOMLINK AppleTestDrag_DragTextPushUndoAction(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODCommandID command, ODULong start, ODULong end, ODPtr text, ODHandle style, StringPtr undoText, StringPtr redoText) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","PushUndoAction"); SOM_TRY #if 0 // create action object for Undo stack UndoInfo* uaction = (UndoInfo*) ODNewPtr(sizeof(UndoInfo), kDefaultHeapID); uaction->displayFrame = frame; uaction->command = command; uaction->start = start; uaction->end = end; uaction->text = text; uaction->style = style; // THERE ARE HELPER FUNCTIONS FOR THIS NOW IN PASCLSTR.H // create Undo and Redo menu item text //ODName* undoMenuText = (ODName*) ODNewPtr(sizeof(ODIText)+strlen(undoText), kDefaultHeapID); //undoMenuText->theScriptCode = smRoman; //undoMenuText->theLangCode = langEnglish; //undoMenuText->textLength = strlen(undoText); //memcpy(undoMenuText->theText, undoText, strlen(undoText)); ODScriptCode script = FontToScript( GetAppFont() ); ODLangCode lang = GetScriptVariable(script, smScriptLang); ODName* undoMenuText = CreateIText( script, lang, undoText); // THERE ARE HELPER FUNCTIONS FOR THIS NOW IN PASCLSTR.H // create Redo menu item text //ODName* redoMenuText = (ODName*) ODNewPtr(sizeof(ODIText)+strlen(redoText), kDefaultHeapID); //redoMenuText->theScriptCode = smRoman; //redoMenuText->theLangCode = langEnglish; //redoMenuText->textLength = strlen(redoText); //memcpy(redoMenuText->theText, redoText, strlen(redoText)); // $$$$ Converted 7/14/94 but not tested // $$$$$ Doubt if this works. Commenting out-NP 1/24/95 // ODName* redoMenuText = PStrToIntl(redoText, kODNULL); // _fSession->GetUndo(ev)->AddActionToHistory(ev, _fPartWrapper, (ODActionData)uaction, // kODSingleAction, undoMenuText, // redoMenuText); // _fUndoCount++; frame->Acquire(ev); #endif /* 0 */ SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextUndoAction(AppleTestDrag_DragText *somSelf, Environment *ev, ODActionData* actionState) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UndoAction"); SOM_TRY #if 0 WASSERTM((_fUndoCount != 0), "Undo unexpected, internal count is zero"); ODBoolean ok = kODFalse; UndoInfo* uaction = (UndoInfo*) actionState; OrderedCollectionIterator dispIter(_fDisplayFrames); for (ODFrame* frame = (ODFrame*)dispIter.First(); dispIter.IsNotComplete(); frame = (ODFrame*)dispIter.Next()) { if (frame == (*uaction).displayFrame) ok = kODTrue; } if (ok) { switch ((*uaction).command) { case kODCommandCut: somSelf->UndoRedoCut(ev, uaction, kUndoIt); break; case kODCommandPaste: somSelf->UndoRedoPaste(ev, uaction, kUndoIt); break; case kODCommandPasteAs: somSelf->UndoRedoPasteLink(ev, uaction, kUndoIt); break; case kODCommandClear: somSelf->UndoRedoClear(ev, uaction, kUndoIt); break; case cDTSampleOne: somSelf->UndoRedoSampleOne(ev, uaction, kUndoIt); break; case cDTSampleTwo: somSelf->UndoRedoSampleTwo(ev, uaction, kUndoIt); break; case cDTTyping: somSelf->UndoRedoTyping(ev, uaction, kUndoIt); break; case cDTStyling: somSelf->UndoRedoStyling(ev, uaction, kUndoIt); break; default: break; } _fUndoCount--; _fRedoCount++; } #endif /* 0 */ SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextRedoAction(AppleTestDrag_DragText *somSelf, Environment *ev, ODActionData* actionState) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RedoAction"); SOM_TRY #if 0 WASSERTM((_fRedoCount != 0), "Redo unexpected, internal count is zero"); ODBoolean ok = kODFalse; UndoInfo* uaction = (UndoInfo*) actionState; OrderedCollectionIterator dispIter(_fDisplayFrames); for (ODFrame* frame = (ODFrame*)dispIter.First(); dispIter.IsNotComplete(); frame = (ODFrame*)dispIter.Next()) { if (frame == (*uaction).displayFrame) ok = kODTrue; } if (ok) { switch ((*uaction).command) { case kODCommandCut: somSelf->UndoRedoCut(ev, uaction, kRedoIt); break; case kODCommandPaste: somSelf->UndoRedoPaste(ev, uaction, kRedoIt); break; case kODCommandPasteAs: somSelf->UndoRedoPasteLink(ev, uaction, kRedoIt); break; case kODCommandClear: somSelf->UndoRedoClear(ev, uaction, kRedoIt); break; case cDTSampleOne: somSelf->UndoRedoSampleOne(ev, uaction, kRedoIt); break; case cDTSampleTwo: somSelf->UndoRedoSampleTwo(ev, uaction, kRedoIt); break; case cDTTyping: somSelf->UndoRedoTyping(ev, uaction, kRedoIt); break; case cDTStyling: somSelf->UndoRedoStyling(ev, uaction, kRedoIt); break; default: break; } _fUndoCount++; _fRedoCount--; } #endif /* 0 */ SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextDisposeActionState(AppleTestDrag_DragText *somSelf, Environment *ev, ODActionData* actionState, ODDoneState doneState) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DisposeActionState"); SOM_TRY // CC: The tests here should be logically inverted; but its not necessary // that both of these counts be non zero. So remove for now. // WASSERTM((_fUndoCount == 0), "Undo unexpected, internal count is zero"); // WASSERTM((_fRedoCount == 0), "Redo unexpected, internal count is zero"); #if 0 UndoInfo* uaction = (UndoInfo*) actionState; (*uaction).displayFrame->Release(ev); // if ((*uaction).text) // ODDisposePtr((Ptr)(*uaction).text); if ((*uaction).style) ODDisposeHandle((Handle) (*uaction).style); ODDisposePtr((ODPtr)uaction); switch (doneState) { case kODDone: case kODRedone: _fUndoCount--; break; case kODUndone: _fRedoCount--; break; default: ; } #endif /* 0 */ SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextWriteActionState(AppleTestDrag_DragText *somSelf, Environment *ev, ODActionData* actionState, ODStorageUnitView* storageUnitView) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","WriteActionState"); ODUnused(actionState); ODUnused(storageUnitView); } SOM_Scope ODActionData SOMLINK AppleTestDrag_DragTextReadActionState(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnitView* storageUnitView) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ReadActionState"); ODActionData data; data._maximum = 0; data._length = 0; data._buffer = kODNULL; return ((ODActionData)data); } //------------------------------------------------------------------------- // Utility Methods //------------------------------------------------------------------------- SOM_Scope void SOMLINK AppleTestDrag_DragTextCommitRelinquishFocus(AppleTestDrag_DragText *somSelf, Environment *ev, ODTypeToken focus, ODFrame* ownerFrame, ODFrame* proposedFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CommitRelinquishFocus"); ODUnused(proposedFrame); SOM_TRY if (focus == _fSession->Tokenize(ev, kODMenuFocus)) { somSelf->RemoveMenus(ev, ownerFrame); _fHasFoci = kODFalse; } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextInstallMenus(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","InstallMenus"); SOM_TRY _fMenuBar->Display(ev); ODFrameFacetIterator* fiter = frame->CreateFacetIterator(ev); somSelf->ClipThis(ev, fiter->First(ev)); TEActivate(_fDocument->theTE); #ifdef SHOW_SCROLL_BARS HiliteControl(_fDocument->vScroll, 0); HiliteControl(_fDocument->hScroll, 0); #endif TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); _fDocument->frameIsActive = true; somSelf->ClipToRoot(ev, fiter->First(ev)); ODDeleteObject(fiter); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextUserCategoryString(AppleTestDrag_DragText *somSelf, Environment *ev, ODName* name) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UserCategoryString"); SOM_TRY ODBoolean result = kODFalse ; ODNameSpaceManager* theNmSpcMgr = _fSession->GetNameSpaceManager(ev); // look it up in the spaceName namespace ODValueNameSpace* userStringNameSpace = (ODValueNameSpace*)theNmSpcMgr->HasNameSpace( ev, kODCategoryUserString ); if (userStringNameSpace) result = myValueNameSpaceGetODName(userStringNameSpace, ev, kODCategoryPlainText, &name ); return result ; SOM_CATCH_ALL SOM_ENDTRY return kODFalse; } SOM_Scope void SOMLINK AppleTestDrag_DragTextRemoveMenus(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RemoveMenus"); SOM_TRY #ifdef SHOW_TEXT_MENU DeleteMenu(140); #endif DeleteMenu(141); DeleteMenu(142); InvalMenuBar(); ODFrameFacetIterator* fiter = frame->CreateFacetIterator(ev); somSelf->ClipThis(ev, fiter->First(ev)); TEDeactivate(_fDocument->theTE); #ifdef SHOW_SCROLL_BARS HiliteControl(_fDocument->vScroll, 255); HiliteControl(_fDocument->hScroll, 255); #endif _fDocument->frameIsActive = false; somSelf->ClipToRoot(ev, fiter->First(ev)); ODDeleteObject(fiter); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextExternalShapeToWindowShape(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet, ODShape* inShape, ODShape* outShape) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ExternalShapeToWindowShape"); SOM_TRY ODTransform* localToGlobal = ODCopyAndRelease(ev, facet->AcquireWindowFrameTransform(ev, kODNULL)); // localToGlobal->Invert(); outShape->CopyFrom(ev, inShape); outShape->Transform(ev, localToGlobal); ODReleaseObject(ev, localToGlobal); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextActivatingWindow(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ActivatingWindow"); SOM_TRY if ( _fNeedsFoci ) { somSelf->ActivateFrame(ev, frame); _fNeedsFoci = kODFalse; // Should check if focus acquired? } if (_fDocument->frameIsActive) { ODFrameFacetIterator* fiter = frame->CreateFacetIterator(ev); somSelf->ClipThis(ev, fiter->First(ev)); #ifdef SHOW_LINK_BORDERS somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif // Since this part was active when its window was deactivated, // turn off the inactive selection before activing the edit record. TEFeatureFlag(teFOutlineHilite, teBitClear, _fDocument->theTE); Rect hiliteRect = (**_fDocument->hiliteRgn).rgnBBox; TEUpdate(&hiliteRect, _fDocument->theTE); TEActivate(_fDocument->theTE); #ifdef SHOW_SCROLL_BARS HiliteControl(_fDocument->vScroll, 0); HiliteControl(_fDocument->hScroll, 0); #endif TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); somSelf->ClipToRoot(ev, fiter->First(ev)); ODDeleteObject(fiter); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextDeactivatingWindow(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DeactivatingWindow"); SOM_TRY if ( _fHasFoci ) _fNeedsFoci = kODTrue; if (_fDocument->frameIsActive) { ODFrameFacetIterator* fiter = frame->CreateFacetIterator(ev); somSelf->ClipThis(ev, fiter->First(ev)); #ifdef SHOW_LINK_BORDERS somSelf->ShowLinkBorder(ev, _fDocument->theFrame, kLinkBorderOff); #endif TEDeactivate(_fDocument->theTE); // Since this part was active when its window was deactivated, // an inactive selection should appear. TEFeatureFlag(teFOutlineHilite, teBitSet, _fDocument->theTE); Rect hiliteRect = (**_fDocument->hiliteRgn).rgnBBox; TEUpdate(&hiliteRect, _fDocument->theTE); #ifdef SHOW_SCROLL_BARS HiliteControl(_fDocument->vScroll, 255); HiliteControl(_fDocument->hScroll, 255); #endif somSelf->ClipToRoot(ev, fiter->First(ev)); ODDeleteObject(fiter); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextClipThis(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ClipThis"); SOM_TRY if ( !facet ) PRINT("DragText %d: ClipThis: facet is null\n", somSelf->GetID(ev)); ODWindow* window = facet->GetWindow(ev); SetPort(window->GetPlatformWindow(ev)); Point xForm = GetAggregateTranslation(ev, facet).AsQDPoint(); ODShape* clipShape = facet->AcquireClipShape(ev, kODNULL); RgnHandle clipRgn = clipShape->CopyQDRegion(ev); OffsetRgn(clipRgn, xForm.h, xForm.v); SetClip(clipRgn); ODReleaseObject(ev, clipShape); ODDisposeHandle((Handle)clipRgn); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextClipToRoot(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ClipToRoot"); SOM_TRY if ( !facet ) PRINT("DragText %d: ClipToRoot: facet is null\n", somSelf->GetID(ev)); ODFacet* pointer = facet; while (pointer->GetContainingFacet(ev) != kODNULL) pointer = pointer->GetContainingFacet(ev); ODWindow* window = pointer->GetWindow(ev); SetPort(window->GetPlatformWindow(ev)); ODShape* clipShape = pointer->AcquireClipShape(ev, kODNULL); SetClip(clipShape->GetQDRegion(ev)); ODReleaseObject(ev, clipShape); SOM_CATCH_ALL SOM_ENDTRY } #if ODDebug /*#define DEBUG_CYCLIC_LINK_UPDATES 1*/ #endif /*ODDebug*/ #ifdef DEBUG_CYCLIC_LINK_UPDATES #include <time.h> static time_t gIdleSeconds = 0; #endif /*DEBUG_CYCLIC_LINK_UPDATES*/ SOM_Scope void SOMLINK AppleTestDrag_DragTextIdle(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","Idle"); SOM_TRY #ifdef DEBUG_CYCLIC_LINK_UPDATES time_t idleSeconds; time(&idleSeconds); if ( !gIdleSeconds ) gIdleSeconds = idleSeconds; if ( (idleSeconds - 6) > gIdleSeconds && _fSrcLink.linkSource ) { gIdleSeconds = idleSeconds; ODLinkKey key; if (_fSrcLink.linkSource->Lock(ev, 0, &key)) { _fSrcLink.linkSource->ContentUpdated(ev, 0x7654, key); _fSrcLink.linkSource->Unlock(ev, key); } } #endif /*DEBUG_CYCLIC_LINK_UPDATES*/ if ( _fDocument && (_fDocument->theFrame == frame) ) { ODFrameFacetIterator* fiter = frame->CreateFacetIterator(ev); if ( fiter->First(ev) ) { somSelf->ClipThis(ev, fiter->First(ev)); #ifdef SHOW_LINK_BORDERS EventRecord dummyEvent; TempODWindow window = frame->AcquireWindow(ev); ODBoolean showLinks = window->ShouldShowLinks(ev); // Show the borders, don't do it if keystroke in buffer if ( (_fLinkBorderStyle == kLinkBorderOff) && ((_fTimeBorderOff+20) < TickCount()) && !EventAvail(keyDownMask, &dummyEvent) && showLinks) { // Turn off the selection, draw the border, turn the selection back on ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; TESetSelect(selStart, selStart, _fDocument->theTE); somSelf->ShowLinkBorder(ev, frame, kLinkBorderOn); TESetSelect(selStart, selEnd, _fDocument->theTE); } if (!showLinks) somSelf->ShowLinkBorder(ev, frame, kLinkBorderOff); #endif if ( _fDocument->frameIsActive ) TEIdle(_fDocument->theTE); somSelf->ClipToRoot(ev, fiter->First(ev)); } else { // $$$$$ MacTech CD: Since this frame has no facets, unregister for idle time. // When a frame is moved across a part boundary, a new part is created, but // the old part does not recieve a DisplayFrameRemoved message. // $$$$$ Talk to Joshua about what to do post-MacTech. PRINT("DragText %d: Idle: Unregistering for Idle events\n", somSelf->GetID(ev)); //_fSession->GetDispatcher(ev)->UnregisterIdle(ev, _fPartWrapper, frame); } ODDeleteObject(fiter); } SOM_CATCH_ALL SOM_ENDTRY } //SOM_Scope void SOMLINK InvalidateFacet(AppleTestDrag_DragText *somSelf, Environment *ev, // ODFacet* facet) //{ // AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); // AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","InvalidateFacet"); // // facet->Invalidate(ev, NULL); //} SOM_Scope void SOMLINK AppleTestDrag_DragTextFrameShapeChanged(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","FrameShapeChanged"); SOM_TRY frame->Invalidate(ev, kODNULL, kODNULL); somSelf->PositionDocumentParts(ev); somSelf->AdjustScrollBar(ev); TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); _fFrameShapeChanged = false; SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextActivateFrame(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ActivateFrame"); SOM_TRY if (!_fHasFoci) { ODBoolean succeeded = false; succeeded = _fSession->GetArbitrator(ev)->RequestFocusSet(ev, _fFocusSet,frame); if (succeeded) { somSelf->InstallMenus(ev, frame); _fHasFoci = true; } } return true; SOM_CATCH_ALL SOM_ENDTRY return kODTrue; } SOM_Scope void SOMLINK AppleTestDrag_DragTextDeactivateFrame(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DeactivateFrame"); SOM_TRY ODArbitrator* arbitrator = _fSession->GetArbitrator(ev); if ( _fHasFoci ) { arbitrator->RelinquishFocusSet(ev, _fFocusSet, frame); _fHasFoci = kODFalse; } arbitrator->RelinquishFocus(ev, _fClipboardFocus, frame); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextAdjustFontMenu(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AdjustFontMenu"); SOM_TRY MenuHandle fontMenuH = _fMenuBar->GetMenu(ev, 141); if ( fontMenuH ) { Str255 fontName; if ( _fLastFont != -1 ) { GetFontName( _fLastFont, fontName ); CheckMarkMenu(fontMenuH, fontName, kODFalse ); } StScrpHandle stylHandle = TEGetStyleScrapHandle(_fDocument->theTE); if ( (**stylHandle).scrpNStyles == 1 ) { _fLastFont = (**stylHandle).scrpStyleTab[0].scrpFont; GetFontName( _fLastFont, fontName ); CheckMarkMenu(fontMenuH, fontName, kODTrue ); } else { _fLastFont = -1; } ODDisposeHandle((Handle)stylHandle); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextHandleFontMenu(AppleTestDrag_DragText *somSelf, Environment *ev, ODUShort item) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","HandleFontMenu"); SOM_TRY Str255 fontName; ODSShort fontNum; MenuHandle fontMenuH = _fMenuBar->GetMenu(ev, 141); GetMenuItemText( fontMenuH, item, fontName ); GetFNum( fontName, &fontNum ); SetTextFont(_fDocument->theTE, fontNum); TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); // If any text was affected, mark the draft as changed ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; if (selEnd > selStart) { _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); } // Update any affected links somSelf->AdjustLinks(ev, selStart, selEnd, selEnd, _fSession->UniqueUpdateID(ev)); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextAdjustSizeMenu(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AdjustSizeMenu"); SOM_TRY MenuHandle sizeMenuH = _fMenuBar->GetMenu(ev, 142); if ( sizeMenuH ) { Str255 fontSizeStr; if ( _fLastSize != 0 ) { NumToString((ODULong) _fLastSize, fontSizeStr); CheckMarkMenu(sizeMenuH, fontSizeStr, kODFalse); } StScrpHandle stylHandle = TEGetStyleScrapHandle(_fDocument->theTE); if ( (**stylHandle).scrpNStyles == 1 ) { _fLastSize = (**stylHandle).scrpStyleTab[0].scrpSize; switch (_fLastSize) { case 0: _fLastSize = 12; case 9: case 10: case 11: case 12: case 14: case 18: case 24: case 36: NumToString((ODULong) _fLastSize, fontSizeStr); CheckMarkMenu(sizeMenuH, fontSizeStr, kODTrue); break; default: _fLastSize = 0; } somSelf->OutlineSizeMenu(ev, (**stylHandle).scrpStyleTab[0].scrpFont); } else { _fLastSize = 0; } ODDisposeHandle((Handle)stylHandle); } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextHandleSizeMenu(AppleTestDrag_DragText *somSelf, Environment *ev, ODUShort item) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","HandleSizeMenu"); SOM_TRY ODSShort fontSize = 0; switch (item) { case 1: fontSize = 9; break; case 2: fontSize = 10; break; case 3: fontSize = 11; break; case 4: fontSize = 12; break; case 5: fontSize = 14; break; case 6: fontSize = 18; break; case 7: fontSize = 24; break; case 8: fontSize = 36; break; default: fontSize = 12; } SetTextSize(_fDocument->theTE, fontSize); TEGetHiliteRgn(_fDocument->hiliteRgn, _fDocument->theTE); // If any text was affected, mark the draft as changed ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; if (selEnd > selStart) { _fDirty = kODTrue; _fDraft->SetChangedFromPrev(ev); } // Update any affected links somSelf->AdjustLinks(ev, selStart, selEnd, selEnd, _fSession->UniqueUpdateID(ev)); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextOutlineSizeMenu(AppleTestDrag_DragText *somSelf, Environment *ev, ODSShort fontNum) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","OutlineSizeMenu"); SOM_TRY MenuHandle menu = _fMenuBar->GetMenu(ev, 142); // (•) Outline the sizes in the font menu that are available if ((fontNum != -1) && RealFont(fontNum, 9)) SetItemStyle( menu, 1, outline ); else SetItemStyle( menu, 1, normal ); if ((fontNum != -1) && RealFont(fontNum, 10)) SetItemStyle( menu, 2, outline ); else SetItemStyle( menu, 2, normal ); if ((fontNum != -1) && RealFont(fontNum, 11)) SetItemStyle( menu, 3, outline ); else SetItemStyle( menu, 3, normal ); if ((fontNum != -1) && RealFont(fontNum, 12)) SetItemStyle( menu, 4, outline ); else SetItemStyle( menu, 4, normal ); if ((fontNum != -1) && RealFont(fontNum, 14)) SetItemStyle( menu, 5, outline ); else SetItemStyle( menu, 5, normal ); if ((fontNum != -1) && RealFont(fontNum, 18)) SetItemStyle( menu, 6, outline ); else SetItemStyle( menu, 6, normal ); if ((fontNum != -1) && RealFont(fontNum, 24)) SetItemStyle( menu, 7, outline ); else SetItemStyle( menu, 7, normal ); if ((fontNum != -1) && RealFont(fontNum, 36)) SetItemStyle( menu, 8, outline ); else SetItemStyle( menu, 8, normal ); SOM_CATCH_ALL SOM_ENDTRY } //------------------------------------------------------------------------------ // DragText: Open //------------------------------------------------------------------------------ SOM_Scope ODID SOMLINK AppleTestDrag_DragTextOpen(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","Open"); SOM_TRY ODWindow* window = kODNULL; ODID windowID = kODNULLID; if (frame) // Doing a View In Window or Open Root { if (frame->IsRoot(ev)) // Create Window For Root Frame { WindowProperties props; if ( BeginGetWindowProperties(ev, frame, &props) ) { ODPlatformWindow platformWindow = NewCWindow(kODNULL, &(props.boundsRect), props.title, kODFalse, props.procID, (WindowPtr)-1L, props.hasCloseBox, props.refCon); window = _fSession->GetWindowState(ev)->RegisterWindowForFrame(ev, platformWindow, frame, props.isRootWindow, // Keeps draft open kODTrue, // Is resizable kODFalse, // Is floating kODTrue, // should save kODTrue, // should dispose props.sourceFrame); EndGetWindowProperties(ev, &props); // Release source frame window->Open(ev); } else { Rect windRect; SetRect(&windRect, 100, 100, 300, 300); ODPlatformWindow platformWindow = NewCWindow(kODNULL, &windRect, "\p", kODFalse, zoomDocProc, (WindowPtr)-1L, true, kODNULL); window = _fSession->GetWindowState(ev)->RegisterWindowForFrame(ev, platformWindow, frame, kODTrue, // Keeps draft open kODTrue, // Is resizable kODFalse, // Is floating kODTrue, // should save kODTrue, // should dispose kODNULL); window->Open(ev); window->AdjustWindowShape(ev); } window->Show(ev); } else // View In Window { window = _fSession->GetWindowState(ev)->AcquireWindow(ev, _fWindowID); if (window) { window->Select(ev); } else { window = somSelf->CreateWindow(ev, frame); _fWindowID = window->GetID(ev); window->Open(ev); window->Show(ev); window->Select(ev); } } } else { window = somSelf->CreateWindow(ev, frame); _fWindowID = window->GetID(ev); window->Open(ev); window->Show(ev); window->Select(ev); } windowID = window->GetID(ev); ODReleaseObject(ev, window); // Because we aren't hanging on to it return windowID; SOM_CATCH_ALL SOM_ENDTRY return kODNULLID; } SOM_Scope ODWindow* SOMLINK AppleTestDrag_DragTextCreateWindow(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* sourceFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CreateWindow"); SOM_TRY Rect windRect; ODPlatformWindow platformWindow = kODNULL; ODWindow* window = kODNULL; if (sourceFrame) { SetRect(&windRect, 100, 100, 300, 300); } else { const ODSShort kOnePageWidth = 600; // Get the menu bar height, for figuring the top of our windows ODSShort mbHeight = 24; //(*(ODSShort*)MBarHeight); //get it from lomem SetRect(&windRect, 4, mbHeight+16, ODQDGlobals.screenBits.bounds.right - 64, ODQDGlobals.screenBits.bounds.bottom - 4); if (windRect.right-windRect.left > kOnePageWidth) { windRect.right = windRect.left + kOnePageWidth; } } ODName* windowName = kODNULL; Str255 pWindowName; if (sourceFrame) windowName = ODGetPartName(ev, sourceFrame, kODNULL); if (windowName==kODNULL || GetITextStringLength(windowName)==0) CopyPascalString(pWindowName, "\pDragText"); else GetITextPString(windowName, pWindowName); if (windowName) DisposeIText(windowName); platformWindow = NewCWindow(kODNULL, &windRect, pWindowName, false, zoomDocProc, (WindowPtr)-1L, true, kODNULL); window = _fSession->GetWindowState(ev)->RegisterWindow(ev, platformWindow, kODFrameObject, (sourceFrame==kODNULL), // Keeps draft open kODTrue, // Is resizable kODFalse, // Is floating kODTrue, // should save kODTrue, // should dispose _fPartWrapper, _fSession->Tokenize(ev, kODViewAsFrame), _fSession->Tokenize(ev, kODViewAsFrame), sourceFrame); return window; SOM_CATCH_ALL SOM_ENDTRY return kODNULL; } //•••••••••••••••••••••••••••••••••• // Utilities //•••••••••••••••••••••••••••••••••• SOM_Scope void SOMLINK AppleTestDrag_DragTextCreateDocument(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CreateDocument"); SOM_TRY TEStyleHandle theStyleHandle; GrafPtr savePort; ODShape* frameShape = kODNULL; RgnHandle FrameRgn; Point xForm; Rect destRect, viewRect, FrameBounds; #ifdef SHOW_SCROLL_BARS Rect scrollRect; #endif // For now we can support only one display frame so if _fDocument is already // present, then the display frame must have been changed. if (_fDocument) { _fDocument->theFrame = frame; _fFrameShapeChanged = true; } else { ODFrameFacetIterator* faceti = frame->CreateFacetIterator(ev); #if ODDebug if ( !faceti->First(ev) ) PRINT("DragText %d: CreateDocument: facet is null\n", somSelf->GetID(ev)); #endif ODWindow* window = faceti->First(ev)->GetWindow(ev); _fDocument = (Document *) ODNewPtrClear(sizeof(Document), kDefaultHeapID); _fDocument->theWindow = window->GetPlatformWindow(ev); _fDocument->theFrame = frame; frame->SetDroppable(ev, kODTrue); GetPort(&savePort); SetPort(_fDocument->theWindow); short saveTxSize = _fDocument->theWindow->txSize; short saveTxFont = _fDocument->theWindow->txFont; short saveTxFace = _fDocument->theWindow->txFace; SetOrigin(0, 0); frameShape = _fDocument->theFrame->AcquireFrameShape(ev, kODNULL); FrameRgn = frameShape->GetQDRegion(ev); ODReleaseObject(ev, frameShape); xForm = GetAggregateTranslation(ev, faceti->First(ev)).AsQDPoint(); FrameBounds = (**FrameRgn).rgnBBox; OffsetRect(&FrameBounds, xForm.h, xForm.v); #ifdef SHOW_SCROLL_BARS scrollRect = FrameBounds; scrollRect.left = scrollRect.right - 16; scrollRect.bottom -= 15; _fDocument->vScroll = NewControl(_fDocument->theWindow, &scrollRect, (ConstStr255Param)"", true, 0, 0, 0, scrollBarProc, (long)_fDocument); scrollRect = FrameBounds; scrollRect.top = scrollRect.bottom - 16; scrollRect.right -= 15; _fDocument->hScroll = NewControl(_fDocument->theWindow, &scrollRect, (ConstStr255Param)"", true, 0, 0, 0, scrollBarProc, (long)_fDocument); #else _fDocument->vScroll = (ControlHandle) -1; // Force address error if dereferenced _fDocument->hScroll = (ControlHandle) -1; #endif viewRect = FrameBounds; #ifdef SHOW_SCROLL_BARS viewRect.right -= 16; viewRect.bottom -= 16; #endif destRect = viewRect; destRect.top += TopMargin; destRect.left += LeftMargin; destRect.bottom = 32767; destRect.right -= RightMargin; // Before calling TEStyleNew, set the port's text attributes to the desired default // values in case _fTextHandle is null TextSize(defaultFontSize); TextFont(defaultFontNum); TextFace(defaultFontFace); _fDocument->theTE = TEStyleNew(&destRect, &viewRect); TEAutoView(true, _fDocument->theTE); // $$$$$ TEFeatureFlag(teFOutlineHilite, TEBitSet, _fDocument->theTE); if (_fTextHandle) { TEActivate(_fDocument->theTE); TESetSelect(32767, 32767, _fDocument->theTE); ODLockHandle((ODHandle) _fTextHandle); TEStyleInsert(*_fTextHandle, ODGetHandleSize((ODHandle) _fTextHandle), _fStylHandle, _fDocument->theTE); ODUnlockHandle((ODHandle) _fTextHandle); TECalText(_fDocument->theTE); TEDeactivate(_fDocument->theTE); } ODDisposeHandle((Handle) _fTextHandle); _fTextHandle = kODNULL; ODDisposeHandle((Handle) _fStylHandle); _fStylHandle = kODNULL; _fDocument->hiliteRgn = ODNewRgn(); theStyleHandle = TEGetStyleHandle(_fDocument->theTE); (**theStyleHandle).teRefCon = (long)_fDocument; _fFrameShapeChanged = true; TextSize(saveTxSize); TextFont(saveTxFont); TextFace(saveTxFace); SetPort(savePort); ODDeleteObject(faceti); // If a destination link was created by Internalize, we can register it now if ( (_fDstLink.link != (ODLink*) kODNULL) && _fDstLink.info.autoUpdate ) { TRY _fDstLink.link->RegisterDependent(ev, _fPartWrapper, _fDstLink.info.change); CATCH_ALL if( ErrorCode()==kODErrBrokenLink ) { PRINT("DragText: ODLink::RegisterDependent() returned broken link error\n"); somSelf->RemoveDstLink(ev); } ENDTRY } } SOM_CATCH_ALL SOM_ENDTRY } /* * This routine computes the size and location of the window's scroll bars * and the TextEdit field given the current size of the window. This routine * is called to initialize these components of the window and to update * the position of these components when the window is resized. */ SOM_Scope void SOMLINK AppleTestDrag_DragTextPositionDocumentParts(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","PositionDocumentParts"); SOM_TRY ODShape* frameShape = kODNULL; RgnHandle FrameRgn; Point xForm; Rect theRect, FrameBounds; GrafPtr savePort; GetPort(&savePort); SetPort(_fDocument->theWindow); SetOrigin(0, 0); { TempODFrameFacetIterator faceti(ev,_fDocument->theFrame); xForm = GetAggregateTranslation(ev, faceti.Current()).AsQDPoint(); } frameShape = _fDocument->theFrame->AcquireFrameShape(ev, kODNULL); FrameRgn = frameShape->GetQDRegion(ev); ODReleaseObject(ev, frameShape); FrameBounds = (**FrameRgn).rgnBBox; OffsetRect(&FrameBounds, xForm.h, xForm.v); #ifdef SHOW_SCROLL_BARS theRect = FrameBounds; theRect.left = theRect.right - 16; theRect.bottom -= 15; (**(_fDocument->vScroll)).contrlRect = theRect; theRect = FrameBounds; theRect.top = theRect.bottom - 16; theRect.right -= 15; (**(_fDocument->hScroll)).contrlRect = theRect; #endif theRect = FrameBounds; // Allow two pixels for drag text frame InsetRect(&theRect, 2, 2); #ifdef SHOW_SCROLL_BARS theRect.right -= 16; theRect.bottom -= 16; #endif (**(_fDocument->theTE)).viewRect = theRect; (**(_fDocument->theTE)).destRect.right = theRect.right - RightMargin; (**(_fDocument->theTE)).destRect.top = theRect.top + TopMargin; (**(_fDocument->theTE)).destRect.left = theRect.left + LeftMargin; TECalText(_fDocument->theTE); SetPort(savePort); SOM_CATCH_ALL SOM_ENDTRY } /* * AdjustScrollBar calculates the current position and maximum value of the * document's scroll bar given the current viewing position and document * text. This routine is called whenever the text is changed or the view * is auto-scrolled. */ SOM_Scope void SOMLINK AppleTestDrag_DragTextAdjustScrollBar(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AdjustScrollBar"); SOM_TRY #ifdef SHOW_SCROLL_BARS short docTop, docBottom, viewTop, viewBottom; short offTop, offBottom; RgnHandle viewRgn; docTop = (**(_fDocument->theTE)).destRect.top; docBottom = (short)(docTop + TEGetHeight(32767, 0, _fDocument->theTE)); viewTop = (**(_fDocument->theTE)).viewRect.top; viewBottom = (**(_fDocument->theTE)).viewRect.bottom; offTop = ((viewTop - (docTop - TopMargin)) + ScrollResolution - 1) / ScrollResolution; offBottom = (((docBottom + BottomMargin) - viewBottom) + ScrollResolution - 1) / ScrollResolution; if (offTop < 0) offTop = 0; if (offBottom < 0) offBottom = 0; _fDocument->vScrollPos = offTop; SetCtlMax(_fDocument->vScroll, offTop + offBottom); SetCtlValue(_fDocument->vScroll, offTop); viewRgn = ODNewRgn(); RectRgn(viewRgn, &(**(_fDocument->theTE)).viewRect); SectRgn(viewRgn, _fDocument->hiliteRgn, _fDocument->hiliteRgn); ODDisposeHandle((Handle)viewRgn); #endif SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextAdjustCursor(AppleTestDrag_DragText *somSelf, Environment *ev, ODPoint* where) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AdjustCursor"); SOM_TRY RgnHandle arrowRgn, iBeamRgn, hiliteRgn; Rect theRect; Point thePoint,theLoc; GrafPtr savePort; GetPort(&savePort); SetPort(_fDocument->theWindow); SetOrigin(0, 0); theLoc = where->AsQDPoint(); #if ODDebug && ODDebugCursor PRINT("AdjustCursor Local H: %d V: %d\n",theLoc.h,theLoc.v); #endif LocalToGlobal(&theLoc); arrowRgn = ODNewRgn(); SetRectRgn(arrowRgn, -32767, -32767, 32767, 32767); iBeamRgn = ODNewRgn(); hiliteRgn = ODNewRgn(); theRect = (**(_fDocument->theTE)).viewRect; #if ODDebug && ODDebugCursor PRINT("AdjustCursor Local L: %d T: %d B: %d R: %d\n",theRect.left,theRect.top,theRect.bottom,theRect.right); #endif LocalToGlobal((Point *)&(theRect.top)); LocalToGlobal((Point *)&(theRect.bottom)); RectRgn(iBeamRgn, &theRect); CopyRgn(_fDocument->hiliteRgn, hiliteRgn); SetPt(&thePoint, 0, 0); LocalToGlobal(&thePoint); OffsetRgn(hiliteRgn, thePoint.h, thePoint.v); DiffRgn(arrowRgn, hiliteRgn, arrowRgn); DiffRgn(arrowRgn, iBeamRgn, arrowRgn); DiffRgn(iBeamRgn, hiliteRgn, iBeamRgn); #if ODDebug && ODDebugCursor PRINT("AdjustCursor Global H: %d V: %d\n",theLoc.h,theLoc.v); PRINT("AdjustCursor Global L: %d T: %d B: %d R: %d\n",theRect.left,theRect.top,theRect.bottom,theRect.right); #endif if (PtInRgn(theLoc, iBeamRgn)) { SetCursor(*GetCursor(iBeamCursor)); } else if (PtInRgn(theLoc, hiliteRgn)) { SetCursor(&(ODQDGlobals.arrow)); } else { SetCursor(&(ODQDGlobals.arrow)); } ODDisposeHandle((Handle)iBeamRgn); ODDisposeHandle((Handle)hiliteRgn); ODDisposeHandle((Handle)arrowRgn); SetPort(savePort); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope short SOMLINK AppleTestDrag_DragTextDoDragText(AppleTestDrag_DragText *somSelf, Environment *ev, ODEventData* event) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","DoDragText"); RgnHandle dragRgn, tempRgn; ODDragAndDrop *dad; ODStorageUnit *dadsu; ODPart *destPart = kODNULL; ODVolatile(destPart); Point xForm; SOM_TRY /* * Wait in the following loop until the user moves the mouse by at * least 4 pixels. If the mouse is released before moving beyond this * minimum threshold, return false. */ if (!WaitMouseMoved(event->where)) { return(false); } /* * Set up the drag region for the drag outline */ dragRgn = ODNewRgn(); CopyRgn(_fDocument->hiliteRgn, dragRgn); SetPt(&xForm, 0, 0); LocalToGlobal(&xForm); OffsetRgn(dragRgn, xForm.h, xForm.v); tempRgn = ODNewRgn(); CopyRgn(dragRgn, tempRgn); InsetRgn(tempRgn, 1, 1); DiffRgn(dragRgn, tempRgn, dragRgn); ODDisposeHandle((Handle)tempRgn); /* * Set up the drag and drop storage unit */ dad = _fSession->GetDragAndDrop(ev); dad->Clear(ev); dadsu = dad->GetContentStorageUnit(ev); if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev))) somSelf->ExternalizeSelection(ev, dadsu, kODCloneCopy); else somSelf->ExternalizeSelection(ev, dadsu, kODCloneCut); #ifdef TRYOUT_PROMISE_FILE { PromiseHFSFlavor thePromise; thePromise.fileType = 'TEXT'; thePromise.fileCreator = 'ttxt'; thePromise.fdFlags = 0; dadsu->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosUndefined); StorageUnitSetPromiseValue(dadsu, ev, kODHFSPromise, 0, sizeof(PromiseHFSFlavor), &thePromise, _fPartWrapper); } #endif somSelf->AddLinkSpecToSU(ev, dadsu); // Remember the selection in case its moved ODSShort origStart = (**(_fDocument->theTE)).selStart; ODSShort origEnd = (**(_fDocument->theTE)).selEnd; // Also remember the original length of the entire text ODSShort origTextLength = (**(_fDocument->theTE)).teLength; // And the offsets of the link destination, if any. ODSShort origDestStart = _fDstLink.start; ODSShort origDestEnd = _fDstLink.end; ODBoolean destLinkIsAfter = ((origDestStart != -1) && (origDestStart >= origEnd)); /* * Do the drag */ // $$$$$ 7/14/94 last parameter changed from EventRecord* to ODEventData* !!!!! ODByteArray dragRgnBA = CreateByteArrayStruct(&dragRgn, sizeof(RgnHandle)); ODByteArray eventBA = CreateByteArrayStruct(&event, sizeof(ODEventData*)); ODDropResult dropResult = dad->StartDrag(ev, _fDocument->theFrame, kODDragImageRegionHandle, &dragRgnBA, &destPart, &eventBA); DisposeByteArrayStruct(dragRgnBA); DisposeByteArrayStruct(eventBA); if ( dropResult == kODDropMove ) PRINT("DragText: StartDrag returned kODDropMove, destPart = %x\n", destPart); else if ( dropResult == kODDropCopy ) PRINT("DragText: StartDrag returned kODDropCopy, destPart = %x\n", destPart); else PRINT("DragText: StartDrag returned dropResult = %d\n", dropResult); if ( dropResult == kODDropMove ) { // Delete the original content. Unfortunately, origStart and origEnd may // no longer identify the original content, because the move may have // deposited text ahead of the original content. Adjust for this if // the current selection is ahead of of origStart. Note that origStart // will equal selStart if the drag was to another part. ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; ODSShort charsAdded = (**(_fDocument->theTE)).teLength - origTextLength; // Note that if text was moved ahead of the original selection, the // original content will have been moved back by the number of characters // inserted. If the text was moved behind the original selection, the // current selection is at least (charsAdded+1) behind the end of the original // selection (+1 because it must have been moved after the first character // beyond the original selection). // Adjust 'charsAdded' in case the move affected the destination link in this // part, either by making it larger or smaller. if ( destLinkIsAfter ) { ODSShort origDestSize = (origDestEnd - origDestStart); ODSShort curDestSize = (_fDstLink.end - _fDstLink.start); charsAdded -= (curDestSize - origDestSize); } if ( selStart <= (origStart+charsAdded) ) { // The text was moved ahead of the original selection, so adjust the // original selection to account for the characters added. // Because white space may have been added, use the total text size // to determine how may characters have been added. origStart += charsAdded; origEnd += charsAdded; } else { // Text was moved behind the original selection, so adjust the current // selection to account for the text about to be deleted. ODSShort origSize = origEnd - origStart; selStart -= origSize; selEnd -= origSize; } // If the frame is not active, must activate TE before inserting // text or the background hilite will not update correctly. if ( !_fDocument->frameIsActive ) TEActivate(_fDocument->theTE); // Select the moved text and delete it. TESetSelect(origStart, origEnd, _fDocument->theTE); TEDelete(_fDocument->theTE); // If content was moved to another part in this document, and the content contained // the source of a link, don't clear the link! // $$$$$ For now, destPart is null if the drop occurred outside of our // document, but that may change! if ( (destPart != kODNULL) && (destPart != _fPartWrapper) ) somSelf->AbandonSourceLinks(ev, origStart, origEnd); if (_fSrcLink.linkSource != ((ODLinkSource*) kODNULL)) PRINT("DragText: Adjusting source link after move\n"); somSelf->AdjustLinks(ev, origStart, origEnd, origStart, _fSession->UniqueUpdateID(ev)); if (destPart == _fPartWrapper) { // Move within this part TESetSelect(selStart, selEnd, _fDocument->theTE); } else { // Move out of this part TESetSelect(selStart, selStart, _fDocument->theTE); } // Undo the TEActivate, if needed. if ( !_fDocument->frameIsActive ) TEDeactivate(_fDocument->theTE); // If text was moved to another part, it seems necessary to invalidate our // frame to force it to update. if ( charsAdded == 0 ) somSelf->InvalAllFrames(ev); } ODReleaseObject(ev, destPart); ODDisposeHandle((Handle)dragRgn); SOM_CATCH_ALL ODReleaseObject(ev, destPart); SOM_ENDTRY return(true); } //------------------------------------------------------------------------------ // DragText: HasExtension //------------------------------------------------------------------------------ SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextHasExtension(AppleTestDrag_DragText *somSelf, Environment *ev, ODType extensionName) { AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","HasExtension"); ODBoolean result = kODFalse; #if DRAGTEXT_SUPPORTS_SCRIPTING SOM_TRY if (!ODISOStrCompare((ODISOStr)extensionName, kODExtSemanticInterface)) return kODTrue; SOM_CATCH_ALL SOM_ENDTRY #endif return result; } //------------------------------------------------------------------------------ // DragText: AcquireExtension //------------------------------------------------------------------------------ SOM_Scope ODExtension* SOMLINK AppleTestDrag_DragTextAcquireExtension(AppleTestDrag_DragText *somSelf, Environment *ev, ODType extensionName) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AcquireExtension"); ODExtension* result = kODNULL; #if DRAGTEXT_SUPPORTS_SCRIPTING SOM_TRY if (!ODISOStrCompare((ODISOStr)extensionName, kODExtSemanticInterface)) { _fSemtIntf->Acquire(ev); result = _fSemtIntf; } SOM_CATCH_ALL SOM_ENDTRY #endif return result; } //------------------------------------------------------------------------------ // DragText: ReleaseExtension //------------------------------------------------------------------------------ SOM_Scope void SOMLINK AppleTestDrag_DragTextReleaseExtension(AppleTestDrag_DragText *somSelf, Environment *ev, ODExtension* extension) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ReleaseExtension"); #if DRAGTEXT_SUPPORTS_SCRIPTING if( extension == _fSemtIntf ) ODDeleteObject(_fSemtIntf); #endif } //------------------------------------------------------------------------------ // DragText: GetSemanticInterface //------------------------------------------------------------------------------ //SOM_Scope ODCPlusSemanticInterface* SOMLINK AppleTestDrag_DragTextGetSemanticInterface(AppleTestDrag_DragText *somSelf, Environment *ev) //{ // AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); // AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","GetSemanticInterface"); // // return _fSemtIntf; //} //------------------------------------------------------------------------------ // DragText: GetTEH //------------------------------------------------------------------------------ //SOM_Scope TEHandle SOMLINK GetTEH(AppleTestDrag_DragText *somSelf, Environment *ev) //{ // AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); // AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","GetTEH"); // // return _fDocument->theTE; //} //------------------------------------------------------------------------------ // DragText: InvalAllFrames() //------------------------------------------------------------------------------ SOM_Scope void SOMLINK AppleTestDrag_DragTextInvalAllFrames(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","InvalAllFrames"); SOM_TRY OrderedCollectionIterator dispIter(_fDisplayFrames); for (ODFrame* aFrame = (ODFrame*)dispIter.First(); dispIter.IsNotComplete(); aFrame = (ODFrame*)dispIter.Next()) { aFrame->Invalidate(ev, (ODShape*)kODNULL, kODNULL) ; } SOM_CATCH_ALL SOM_ENDTRY } // InvalAllFrames() //------------------------------------------------------------------------------ // DragText: GetDragTextFrame() //------------------------------------------------------------------------------ //SOM_Scope ODFrame* SOMLINK GetDragTextFrame(AppleTestDrag_DragText *somSelf, Environment *ev) //{ // AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); // AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","GetDragTextFrame"); // // return _fDocument->theFrame ; //} //------------------------------------------------------------------------------ // DragText: AdjustMenus() //------------------------------------------------------------------------------ SOM_Scope void SOMLINK AppleTestDrag_DragTextAdjustMenus(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AdjustMenus"); SOM_TRY TEHandle myTE = _fDocument->theTE; ODBoolean isSelection; ODBoolean canSelectAll; ODBoolean canShowLinkInfo; // DON'T DO THIS! FOR LOCALISABILITY, READ THE TEXT OUT OF A RESOURCE AND // USE THE CURRENT SYSTEM SCRIPT AND CURRENT SYSTEM LANGUAGE. ODIText* menuItem = CreateIText(smRoman, langEnglish, "About DragText…"); _fMenuBar->SetItemString(ev, kODCommandAbout, menuItem); DisposeIText(menuItem); isSelection = (*myTE)->selEnd > (*myTE)->selStart; _fMenuBar->EnableCommand(ev, kODCommandClear, isSelection); ODArbitrator* arbitrator = _fSession->GetArbitrator(ev); ODFrame* clipboardFocus = arbitrator->AcquireFocusOwner(ev, _fClipboardFocus); if ( (frame == clipboardFocus) || (arbitrator->RequestFocus(ev, _fClipboardFocus, frame)) ) { ODBoolean canPaste = kODFalse; #ifdef SUPPORT_TESTDRAG_KIND canPaste = ValueOnClipboard(ev, kODKindTestDrag, _fSession); #endif canPaste |= ValueOnClipboard(ev, kODAppleTEXT, _fSession); _fMenuBar->EnableCommand(ev, kODCommandCut, isSelection); _fMenuBar->EnableCommand(ev, kODCommandCopy, isSelection); _fMenuBar->EnableCommand(ev, kODCommandPaste, canPaste); _fMenuBar->EnableCommand(ev, kODCommandPasteAs, canPaste); } ODReleaseObject(ev, clipboardFocus); canSelectAll = ((*myTE)->teLength > 0) && (((*myTE)->selStart > 0) || ((*myTE)->selEnd < (*myTE)->teLength)); _fMenuBar->EnableCommand(ev, kODCommandSelectAll, canSelectAll); canShowLinkInfo = somSelf->SelectionInLinkSource(ev) || somSelf->SelectionInLinkDestination(ev); Str255 aStr; CopyPascalString(aStr, canShowLinkInfo ? "\pLink Info" : "\pPart Info"); ODScriptCode script = FontToScript( GetSysFont() ); ODLangCode lang = GetScriptVariable(script, smScriptLang); ODIText* menuText = CreateIText(script, lang, aStr); _fMenuBar->SetItemString(ev, kODCommandGetPartInfo, menuText); DisposeIText(menuText); _fMenuBar->EnableCommand(ev, kODCommandGetPartInfo, canShowLinkInfo); somSelf->AdjustFontMenu(ev); somSelf->AdjustSizeMenu(ev); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextCommonInitDragText(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* su) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CommonInitDragText"); SOM_TRY _fSession = su->GetSession(ev); AppleTestDrag_SemtIntf* face = new AppleTestDrag_SemtIntf; face->InitSemtIntf(ev, somSelf, _fSession); _fSemtIntf = face; _fFocusSet = _fSession->GetArbitrator(ev)->CreateFocusSet(ev); _fFocusSet->Add(ev, _fSession->Tokenize(ev, kODKeyFocus)); _fFocusSet->Add(ev, _fSession->Tokenize(ev, kODMenuFocus)); _fFocusSet->Add(ev, _fSession->Tokenize(ev, kODSelectionFocus)); _fClipboardFocus = _fSession->Tokenize(ev, kODClipboardFocus); _fDisplayFrames = new OrderedCollection; #ifdef SHOW_TEXT_MENU _fTextMenu = NewMenu(140,"\pText"); if (!_fFontMenu) WARN("Error creating Text menu"); #else _fTextMenu = kODNULL; #endif _fFontMenu = NewMenu(141,"\pFont"); if (!_fFontMenu) WARN("Error creating Font menu"); _fSizeMenu = NewMenu(142,"\pSize"); if (!_fSizeMenu) WARN("Error creating Size menu"); _fMenuBar = _fSession->GetWindowState(ev)->CopyBaseMenuBar(ev); #ifdef SHOW_TEXT_MENU AppendMenu(_fTextMenu,"\pSample One"); _fMenuBar->RegisterCommand(ev, cDTSampleOne, 140, 1); AppendMenu(_fTextMenu,"\pSample Two"); _fMenuBar->RegisterCommand(ev, cDTSampleTwo, 140, 2); #endif AppendResMenu(_fFontMenu,'FOND'); AppendMenu(_fSizeMenu,"\p9"); AppendMenu(_fSizeMenu,"\p10"); AppendMenu(_fSizeMenu,"\p11"); AppendMenu(_fSizeMenu,"\p12"); AppendMenu(_fSizeMenu,"\p14"); AppendMenu(_fSizeMenu,"\p18"); AppendMenu(_fSizeMenu,"\p24"); AppendMenu(_fSizeMenu,"\p36"); #ifdef SHOW_TEXT_MENU _fMenuBar->AddMenuLast(ev, 140, _fTextMenu, _fPartWrapper); #endif _fMenuBar->AddMenuLast(ev, 141, _fFontMenu, _fPartWrapper); _fMenuBar->AddMenuLast(ev, 142, _fSizeMenu, _fPartWrapper); #ifdef SIHELPER_IMPLEMENTED // $$$$$ // _fSemtIntf = new ODCPlusSemanticInterface(); // _fSemtIntf->InitCPlusSemanticInterface(ev, _fPartWrapper); #endif // somSelf->InstallObjectAccessors(ev); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextExternalizeSelection(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* su, ODCloneKind cloneKind) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ExternalizeSelection"); SOM_TRY // Write out the current selection to the argument storage unit // This routine can be called to write to an existing storage unit; however, // only the values written will be changed. #ifdef SUPPORT_TESTDRAG_KIND ODStorageUnitRef aSURef; #endif ODSShort selStart = (**(_fDocument->theTE)).selStart; ODSShort selEnd = (**(_fDocument->theTE)).selEnd; ODBoolean srcLinkIn = kODFalse; ODBoolean dstLinkIn = kODFalse; ODULong linkCount = 0; if ( !(cloneKind == kODCloneToLink) ) { if ( _fSrcLink.linkSource != (ODLinkSource*) kODNULL ) srcLinkIn = IncludedInRange(_fSrcLink.start, _fSrcLink.end, selStart, selEnd); if ( _fDstLink.link != (ODLink*) kODNULL ) dstLinkIn = IncludedInRange(_fDstLink.start, _fDstLink.end, selStart, selEnd); if ( srcLinkIn ) linkCount += 1; if ( dstLinkIn ) linkCount += 1; } ODDraft* toDraft = su->GetDraft(ev); ODDraftKey draftKey = _fDraft->BeginClone(ev, toDraft, kODNULL, cloneKind); TRY #ifdef SUPPORT_TESTDRAG_KIND ODStorageUnit* testDragSU; #endif // Add the contents property to argument storage unit SUForceFocus(ev, su, kODPropContents, kODNULL); #ifdef SUPPORT_TESTDRAG_KIND // If a test drag storage unit already exists, re-use it rather than // create a new one so this routine can be used to update a link. SUForceFocus(ev, su, kODPropContents, kODKindTestDrag); if ( su->GetSize(ev) == sizeof(ODStorageUnitRef) ) { StorageUnitGetValue(su, ev, sizeof(ODStorageUnitRef), &aSURef); testDragSU = toDraft->AcquireStorageUnit(ev, su->GetIDFromStorageUnitRef(ev, aSURef)); } else { testDragSU = toDraft->CreateStorageUnit(ev); // Add the TestDrag content value (a reference to another storage unit) su->GetStrongStorageUnitRef(ev, testDragSU->GetID(ev), aSURef); StorageUnitSetValue(su, ev, sizeof(ODStorageUnitRef), aSURef); } #endif WriteValueType(ev, su, kODPropContents, kODApplestxt, _fDocument->theTE, kODTrue); WriteValueType(ev, su, kODPropContents, kODAppleTEXT, _fDocument->theTE, kODTrue); #ifdef SUPPORT_TESTDRAG_KIND // …and to the TestDrag storage unit WriteValueType(ev, testDragSU, kDragTextPropText, kODAppleTEXT, _fDocument->theTE, kODTrue); WriteValueType(ev, testDragSU, kDragTextPropStyl, kODApplestyl, _fDocument->theTE, kODTrue); #endif #ifdef SUPPORT_TESTDRAG_KIND if ( linkCount ) { // Write out the source and destination links if ( srcLinkIn ) { ODID clonedLinkSourceID = _fDraft->Clone(ev, draftKey, _fSrcLink.linkSource->GetID(ev), 0, 0); SUForceFocus(ev, testDragSU, kDragTextPropSourceLink, kDragTextValue); testDragSU->GetStrongStorageUnitRef(ev, clonedLinkSourceID, aSURef); StorageUnitSetValue(testDragSU, ev, sizeof(ODStorageUnitRef),aSURef); ODSShort srcLinkStart = _fSrcLink.start - selStart; StorageUnitSetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &srcLinkStart); ODSShort srcLinkEnd = _fSrcLink.end - selStart; StorageUnitSetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &srcLinkEnd); StorageUnitSetValue(testDragSU, ev, sizeof(ODULong), (ODValue) &_fSrcLink.change); } if ( dstLinkIn ) { ODID clonedLinkID = _fDraft->Clone(ev, draftKey, _fDstLink.link->GetID(ev), 0, 0); SUForceFocus(ev, testDragSU, kDragTextPropDestLink, kDragTextValue); testDragSU->GetStrongStorageUnitRef(ev, clonedLinkID, aSURef); StorageUnitSetValue(testDragSU, ev, sizeof(ODStorageUnitRef), aSURef); ODSShort dstLinkStart = _fDstLink.start - selStart; StorageUnitSetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &dstLinkStart); ODSShort dstLinkEnd = _fDstLink.end - selStart; StorageUnitSetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &dstLinkEnd); ODType kind = _fDstLink.info.kind; _fDstLink.info.kind = (ODType) ODISOStrLength(kind) + 1; StorageUnitSetValue(testDragSU, ev, sizeof(ODLinkInfo), (ODValue) &_fDstLink.info); StorageUnitSetValue(testDragSU, ev, (ODULong) _fDstLink.info.kind, (ODValue) kind); _fDstLink.info.kind = kind; } } testDragSU->Release(ev); #endif CATCH_ALL _fDraft->AbortClone(ev, draftKey); RERAISE; ENDTRY _fDraft->EndClone(ev, draftKey); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextCanPasteLink(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* contentSU, ODBoolean isMyContent, ODSShort pasteStart, ODSShort pasteEnd) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CanPasteLink"); ODBoolean result = kODFalse; #ifdef SUPPORT_TESTDRAG_KIND if (HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev))) { result = (_fDstLink.link == (ODLink*) kODNULL) && LinkSpecInSU(ev, contentSU); if ( result ) { // A link spec is present, and this part can support a link destination if ( _fSrcLink.linkSource != kODNULL ) { // Do not allow the destination to overlap an existing link source result = !RangesOverlap(pasteStart,pasteEnd,_fSrcLink.start,_fSrcLink.end); } else if ( isMyContent ) { // The link spec is to a potential link source in this part. // Do not allow the destination to overlap the potential link source if (_fSrcLink.end > _fSrcLink.start) // Must always be true! result = !RangesOverlap(pasteStart,pasteEnd,_fSrcLink.start,_fSrcLink.end); } } } #endif return result; } SOM_Scope void SOMLINK AppleTestDrag_DragTextInstallObjectAccessors(AppleTestDrag_DragText *somSelf, Environment *ev) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","InstallObjectAccessors"); } SOM_Scope void SOMLINK AppleTestDrag_DragTextsomInit(AppleTestDrag_DragText *somSelf) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","somInit"); AppleTestDrag_DragText_parents_somInit(somSelf); _fHasFoci = kODFalse; _fNeedsFoci = kODFalse; _fFocusSet = kODNULL; _fClipboardFocus = kODNullFocus; _fDirty = kODFalse; _fWindowID = 0; _fDocument = NULL; _fTextHandle = NULL; _fStylHandle = NULL; _fExtTransStore.x = 0; // ••• hack! so we can tell if frame has been dragged _fExtTransStore.y = 0; _fLastFont = -1; _fLastSize = 0; _fFrameShapeChanged = true; _fDisplayFrames = kODNULL; _fUndoCount = 0; _fRedoCount = 0; _fSrcLink.linkSource = (ODLinkSource*) kODNULL; _fSrcLink.start = -1; _fSrcLink.end = -1; _fSrcLink.change = kODUnknownUpdate; _fDstLink.link = (ODLink*) kODNULL; _fDstLink.start = -1; _fDstLink.end = -1; _fDstLink.info.kind = (ODType) kODNULL; _fLinkBorderStyle = kLinkBorderOff; _fTimeBorderOff = 0; _fDraft = kODNULL; _fTestDragSU = kODNULL; // _fSemtIntf = kODNULL; _fPartWrapper = kODNULL; } SOM_Scope void SOMLINK AppleTestDrag_DragTextsomUninit(AppleTestDrag_DragText *somSelf) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","somUninit"); Environment* ev = somGetGlobalEnvironment(); // DragText::ReleaseExtension will get called as a result of the refcount of // _fSemtIntf going to zero. ReleaseExtension will then delete the object. _fSemtIntf->Release(ev); ODDeleteObject(_fDisplayFrames); if ( _fDocument && _fDocument->theTE ) TEDispose(_fDocument->theTE); ODDisposePtr((Ptr) _fDocument); ODDisposeHandle((Handle) _fTextHandle); ODDisposeHandle((Handle) _fStylHandle); if ( _fMenuBar ) { #ifdef SHOW_TEXT_MENU _fMenuBar->RemoveMenu(ev, 140); #endif _fMenuBar->RemoveMenu(ev, 141); _fMenuBar->RemoveMenu(ev, 142); _fMenuBar->Release(ev); } if (_fTextMenu) DisposeMenu(_fTextMenu); if (_fFontMenu) DisposeMenu(_fFontMenu); if (_fSizeMenu) DisposeMenu(_fSizeMenu); ODDeleteObject(_fFocusSet); AppleTestDrag_DragText_parents_somUninit(somSelf); } SOM_Scope void SOMLINK AppleTestDrag_DragTextContainingPartPropertiesUpdated(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODStorageUnit* propertyUnit) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ContainingPartPropertiesUpdated"); ODUnused(frame); ODUnused(propertyUnit); } SOM_Scope ODStorageUnit* SOMLINK AppleTestDrag_DragTextAcquireContainingPartProperties(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AcquireContainingPartProperties"); ODUnused(frame); ODSetSOMException(ev, kODErrCannotEmbed); return kODNULL; } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextRevealFrame(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* embeddedFrame, ODShape* revealShape) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RevealFrame"); ODUnused(embeddedFrame); ODUnused(revealShape); ODSetSOMException(ev, kODErrInvalidFrame); return kODFalse; } SOM_Scope void SOMLINK AppleTestDrag_DragTextEmbeddedFrameSpec(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* embeddedFrame, ODObjectSpec* spec) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","EmbeddedFrameSpec"); ODUnused(embeddedFrame); ODUnused(spec); ODSetSOMException(ev, kODErrInvalidFrame); } SOM_Scope ODEmbeddedFramesIterator* SOMLINK AppleTestDrag_DragTextCreateEmbeddedFramesIterator(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CreateEmbeddedFramesIterator"); ODUnused(frame); ODSetSOMException(ev, kODErrCannotEmbed); return kODNULL; } SOM_Scope void SOMLINK AppleTestDrag_DragTextAttachSourceFrame(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODFrame* sourceFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AttachSourceFrame"); ODUnused(frame); ODUnused(sourceFrame); } SOM_Scope void SOMLINK AppleTestDrag_DragTextViewTypeChanged(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ViewTypeChanged"); ODUnused(frame); } SOM_Scope void SOMLINK AppleTestDrag_DragTextPresentationChanged(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","PresentationChanged"); ODUnused(frame); } SOM_Scope void SOMLINK AppleTestDrag_DragTextSequenceChanged(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","SequenceChanged"); ODUnused(frame); } SOM_Scope ODInfoType SOMLINK AppleTestDrag_DragTextReadPartInfo(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODStorageUnitView* storageUnitView) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ReadPartInfo"); ODUnused(frame); ODUnused(storageUnitView); return kODNULL; } SOM_Scope void SOMLINK AppleTestDrag_DragTextWritePartInfo(AppleTestDrag_DragText *somSelf, Environment *ev, ODInfoType partInfo, ODStorageUnitView* storageUnitView) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","WritePartInfo"); ODUnused(partInfo); ODUnused(storageUnitView); } SOM_Scope void SOMLINK AppleTestDrag_DragTextClonePartInfo(AppleTestDrag_DragText *somSelf, Environment *ev, ODDraftKey key, ODInfoType partInfo, ODStorageUnitView* storageUnitView, ODFrame* scopeFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ClonePartInfo"); ODUnused(key); ODUnused(partInfo); ODUnused(storageUnitView); ODUnused(scopeFrame); } SOM_Scope ODFrame* SOMLINK AppleTestDrag_DragTextRequestEmbeddedFrame(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* containingFrame, ODFrame* baseFrame, ODShape* frameShape, ODPart* embedPart, ODTypeToken viewType, ODTypeToken presentation, ODBoolean isOverlaid) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RequestEmbeddedFrame"); ODUnused(containingFrame); ODUnused(baseFrame); ODUnused(frameShape); ODUnused(embedPart); ODUnused(viewType); ODUnused(presentation); ODUnused(isOverlaid); ODSetSOMException(ev, kODErrCannotEmbed); return kODNULL; } SOM_Scope void SOMLINK AppleTestDrag_DragTextRemoveEmbeddedFrame(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* embeddedFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RemoveEmbeddedFrame"); ODUnused(embeddedFrame); } SOM_Scope ODShape* SOMLINK AppleTestDrag_DragTextRequestFrameShape(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* embeddedFrame, ODShape* frameShape) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","RequestFrameShape"); ODUnused(embeddedFrame); return (frameShape); } SOM_Scope void SOMLINK AppleTestDrag_DragTextUsedShapeChanged(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* embeddedFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","UsedShapeChanged"); ODUnused(embeddedFrame); } SOM_Scope ODShape* SOMLINK AppleTestDrag_DragTextAdjustBorderShape(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* embeddedFacet, ODShape* shape) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AdjustBorderShape"); ODUnused(embeddedFacet); return shape; } SOM_Scope void SOMLINK AppleTestDrag_DragTextFacetAdded(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","FacetAdded"); SOM_TRY somSelf->CreateDocument(ev, facet->GetFrame(ev)); // PRINT("DragText %d: FacetAdded: Registering for Idle events\n", somSelf->GetID(ev)); _fSession->GetDispatcher(ev)->RegisterIdle(ev, _fPartWrapper, facet->GetFrame(ev), kDTIdleFrequency); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextFacetRemoved(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","FacetRemoved"); ODUnused(facet); SOM_TRY // PRINT("DragText %d: FacetRemoved: Unregistering for Idle events\n", somSelf->GetID(ev)); _fSession->GetDispatcher(ev)->UnregisterIdle(ev, _fPartWrapper, facet->GetFrame(ev)); SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextCanvasChanged(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CanvasChanged"); ODUnused(facet); } SOM_Scope void SOMLINK AppleTestDrag_DragTextCanvasUpdated(AppleTestDrag_DragText *somSelf, Environment *ev, ODCanvas* canvas) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CanvasUpdated"); ODUnused(canvas); } SOM_Scope void SOMLINK AppleTestDrag_DragTextHighlightChanged(AppleTestDrag_DragText *somSelf, Environment *ev, ODFacet* facet) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","HighlightChanged"); ODUnused(facet); } SOM_Scope ODULong SOMLINK AppleTestDrag_DragTextGetPrintResolution(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","GetPrintResolution"); ODUnused(frame); return (0); } SOM_Scope void SOMLINK AppleTestDrag_DragTextEmbeddedFrameUpdated(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame, ODUpdateID change) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","EmbeddedFrameUpdated"); ODUnused(frame); ODUnused(change); } SOM_Scope void SOMLINK AppleTestDrag_DragTextLinkStatusChanged(AppleTestDrag_DragText *somSelf, Environment *ev, ODFrame* frame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","LinkStatusChanged"); ODUnused(frame); } SOM_Scope ODBoolean SOMLINK AppleTestDrag_DragTextBeginRelinquishFocus(AppleTestDrag_DragText *somSelf, Environment *ev, ODTypeToken focus, ODFrame* ownerFrame, ODFrame* proposedFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","BeginRelinquishFocus"); ODUnused(focus); ODUnused(ownerFrame); ODUnused(proposedFrame); return kODTrue; } SOM_Scope void SOMLINK AppleTestDrag_DragTextAbortRelinquishFocus(AppleTestDrag_DragText *somSelf, Environment *ev, ODTypeToken focus, ODFrame* ownerFrame, ODFrame* proposedFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","AbortRelinquishFocus"); ODUnused(focus); ODUnused(ownerFrame); ODUnused(proposedFrame); } SOM_Scope void SOMLINK AppleTestDrag_DragTextFocusAcquired(AppleTestDrag_DragText *somSelf, Environment *ev, ODTypeToken focus, ODFrame* ownerFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","FocusAcquired"); ODUnused(focus); ODUnused(ownerFrame); } SOM_Scope void SOMLINK AppleTestDrag_DragTextFocusLost(AppleTestDrag_DragText *somSelf, Environment *ev, ODTypeToken focus, ODFrame* ownerFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","FocusLost"); ODUnused(focus); ODUnused(ownerFrame); if (focus == _fSession->Tokenize(ev, kODMenuFocus)) { somSelf->RemoveMenus(ev, ownerFrame); _fHasFoci = kODFalse; } } //------------------------------------------------------------------------- // DragText: CloneInto (Override) //------------------------------------------------------------------------- SOM_Scope void SOMLINK AppleTestDrag_DragTextCloneInto(AppleTestDrag_DragText *somSelf, Environment *ev, ODDraftKey key, ODStorageUnit* storageUnit, ODFrame* scopeFrame) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","CloneInto"); // If one of our properties already exists, this object has been cloned already if ( storageUnit->Exists(ev, kODPropContents, kODNULL, 0) ) return; SOM_TRY parent_CloneInto(somSelf, ev, key, storageUnit, scopeFrame); if ( _fDocument != kODNULL ) { StScrpHandle stylHandle; Handle textHandle; char textState; ODULong textSize; void* textPtr; ODStorageUnitRef aSURef; ODID scopeFrameID = ( scopeFrame == kODNULL ? 0 : scopeFrame->GetID(ev) ); ODID clonedID; #ifdef SUPPORT_TESTDRAG_KIND ODStorageUnit* testDragSU = storageUnit->GetDraft(ev)->CreateStorageUnit(ev); #endif textHandle = (**(_fDocument->theTE)).hText; textSize = (**(_fDocument->theTE)).teLength; textState = HGetState(textHandle); textPtr = ODLockHandle((ODHandle) textHandle); // Write the text to the content property SUFocusAndSetValue(ev, storageUnit, kODPropContents, kODAppleTEXT, (ODValue) textPtr, textSize); #ifdef SUPPORT_TESTDRAG_KIND // …and to the TestDrag storage unit SUFocusAndSetValue(ev, testDragSU, kDragTextPropText, kODAppleTEXT, (ODValue) textPtr, textSize); #endif HSetState(textHandle, textState); if ( textSize > 0 ) { short saveStart = (**(_fDocument->theTE)).selStart; short saveEnd = (**(_fDocument->theTE)).selEnd; TESetSelect(0, 32767, _fDocument->theTE); stylHandle = TEGetStyleScrapHandle(_fDocument->theTE); ODULong stylSize = ODGetHandleSize((ODHandle) stylHandle); void* stylPtr = ODLockHandle((ODHandle) stylHandle); // Write the styl information to the content property SUFocusAndSetValue(ev, storageUnit, kODPropContents, kODApplestyl, (ODValue) stylPtr, stylSize); #ifdef SUPPORT_TESTDRAG_KIND // …and to the TestDrag storage unit SUFocusAndSetValue(ev, testDragSU, kDragTextPropStyl, kODApplestyl, (ODValue) stylPtr, stylSize); #endif ODUnlockHandle((ODHandle)stylHandle); ODDisposeHandle((Handle)stylHandle); TESetSelect(saveStart, saveEnd, _fDocument->theTE); } #ifdef SUPPORT_TESTDRAG_KIND // // Write out the source and destination links // if (_fSrcLink.linkSource != (ODLinkSource*) kODNULL) { clonedID = _fDraft->Clone(ev, key, _fSrcLink.linkSource->GetID(ev), 0, scopeFrameID); PRINT("Cloned linkSource ID = %d to ID = %d\n", _fSrcLink.linkSource->GetID(ev), clonedID); if ( clonedID != kODNULLID ) { SUForceFocus(ev, testDragSU, kDragTextPropSourceLink, kDragTextValue); testDragSU->GetStrongStorageUnitRef(ev, clonedID, aSURef); StorageUnitSetValue(testDragSU, ev, sizeof(ODStorageUnitRef), aSURef); StorageUnitSetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &_fSrcLink.start); StorageUnitSetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &_fSrcLink.end); StorageUnitSetValue(testDragSU, ev, sizeof(ODULong), (ODValue) &_fSrcLink.change); } } if (_fDstLink.link != (ODLink*) kODNULL) { clonedID = _fDraft->Clone(ev, key, _fDstLink.link->GetID(ev), 0, scopeFrameID); PRINT("Cloned link ID = %d to ID = %d\n", _fDstLink.link->GetID(ev), clonedID); if ( clonedID != kODNULLID ) { SUForceFocus(ev, testDragSU, kDragTextPropDestLink, kDragTextValue); testDragSU->GetStrongStorageUnitRef(ev, clonedID, aSURef); StorageUnitSetValue(testDragSU, ev, sizeof(ODStorageUnitRef), aSURef); StorageUnitSetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &_fDstLink.start); StorageUnitSetValue(testDragSU, ev, sizeof(ODSShort), (ODValue) &_fDstLink.end); ODType kind = _fDstLink.info.kind; _fDstLink.info.kind = (ODType) ODISOStrLength(kind) + 1; StorageUnitSetValue(testDragSU, ev, sizeof(ODLinkInfo), (ODValue) &_fDstLink.info); StorageUnitSetValue(testDragSU, ev, (ODULong) _fDstLink.info.kind, (ODValue) kind); _fDstLink.info.kind = kind; } } SUForceFocus(ev, storageUnit, kODPropContents, kODKindTestDrag); storageUnit->GetStrongStorageUnitRef(ev, testDragSU->GetID(ev), aSURef); StorageUnitSetValue(storageUnit, ev, sizeof(ODStorageUnitRef), aSURef); #endif #ifdef SUPPORT_TESTDRAG_KIND ODReleaseObject(ev, testDragSU); #endif } SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextExternalizeKinds(AppleTestDrag_DragText *somSelf, Environment *ev, ODTypeList* kindset) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ExternalizeKinds"); ODUnused(kindset); } SOM_Scope void SOMLINK AppleTestDrag_DragTextChangeKind(AppleTestDrag_DragText *somSelf, Environment *ev, ODType kind) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","ChangeKind"); ODUnused(kind); } SOM_Scope void SOMLINK AppleTestDrag_DragTextInitPart(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* storageUnit, ODPart* partWrapper) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","InitPart"); SOM_TRY _fPartWrapper = partWrapper; parent_InitPart(somSelf, ev, storageUnit, partWrapper); somSelf->CommonInitDragText(ev, storageUnit); storageUnit->AddProperty(ev, kODPropContents); #ifdef SUPPORT_TESTDRAG_KIND storageUnit->AddValue(ev, kODKindTestDrag); #else storageUnit->AddValue(ev, kODAppleTEXT); #endif _fDraft = storageUnit->GetDraft(ev); #ifdef SUPPORT_TESTDRAG_KIND _fTestDragSU = _fDraft->CreateStorageUnit(ev); #endif _fDirty = kODTrue; SOM_CATCH_ALL SOM_ENDTRY } SOM_Scope void SOMLINK AppleTestDrag_DragTextInitPartFromStorage(AppleTestDrag_DragText *somSelf, Environment *ev, ODStorageUnit* storageUnit, ODPart* partWrapper) { AppleTestDrag_DragTextData *somThis = AppleTestDrag_DragTextGetData(somSelf); AppleTestDrag_DragTextMethodDebug("AppleTestDrag_DragText","InitPartFromStorage"); SOM_TRY _fPartWrapper = partWrapper; parent_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper); somSelf->CommonInitDragText(ev, storageUnit); Size textSize, stylSize; ODStorageUnit *partSU; #ifdef SUPPORT_TESTDRAG_KIND ODStorageUnitRef aSURef; #endif // $$$$$ OBSOLETE: Volatile(partSU); partSU = somSelf->GetStorageUnit(ev); _fDraft = partSU->GetDraft(ev); #ifdef SUPPORT_TESTDRAG_KIND // $$$$$ This part should initialize from the first value kind that it supports, // $$$$$ not necessarily its native representation. // This editor's preference is for content of type kODKindTestDrag, so look for it first if ( partSU->Exists(ev, kODPropContents, kODKindTestDrag, 0) ) { partSU->Focus(ev, kODPropContents,kODPosSame,kODKindTestDrag,1,kODPosFirstSib); StorageUnitGetValue(partSU, ev, sizeof(ODStorageUnitRef),&aSURef); ASSERT(partSU->IsValidStorageUnitRef(ev, aSURef), kODErrInvalidStorageUnitRef); _fTestDragSU = _fDraft->AcquireStorageUnit(ev, partSU->GetIDFromStorageUnitRef(ev, aSURef)); // TEXT property won't exist in stationery if ( SUExistsThenFocus(ev, _fTestDragSU, kDragTextPropText, kODAppleTEXT) ) { textSize = _fTestDragSU->GetSize(ev); if (textSize > 0) { _fTextHandle = (Handle) ODNewHandle(textSize); ODLockHandle((ODHandle) _fTextHandle); StorageUnitGetValue(_fTestDragSU, ev, textSize, (ODValue)*_fTextHandle); ODUnlockHandle((ODHandle) _fTextHandle); } } // styl property won't exist in stationery if ( SUExistsThenFocus(ev, _fTestDragSU, kDragTextPropStyl, kODApplestyl) ) { stylSize = _fTestDragSU->GetSize(ev); if (stylSize > 0) { _fStylHandle = (StScrpHandle)ODNewHandle(stylSize); ODLockHandle((ODHandle) _fStylHandle); StorageUnitGetValue(_fTestDragSU, ev, stylSize, (ODValue)*_fStylHandle); ODUnlockHandle((ODHandle) _fStylHandle); } } // // Read in the display frame; there can be only one but there may be none. // if ( SUExistsThenFocus(ev, _fTestDragSU, kODPropDisplayFrames, kODWeakStorageUnitRefs) ) { if ( _fTestDragSU->GetSize(ev) > 0 ) { TRY StorageUnitGetValue(_fTestDragSU, ev, sizeof(ODStorageUnitRef), (ODValue)&aSURef); if ( _fTestDragSU->IsValidStorageUnitRef(ev, aSURef) ) { ODFrame* aFrame = _fDraft->AcquireFrame(ev, _fTestDragSU->GetIDFromStorageUnitRef(ev, aSURef)); _fDisplayFrames->AddLast((ElementType)aFrame); } CATCH_ALL ENDTRY } } // // Read in the source and destination links // if ( SUExistsThenFocus(ev, _fTestDragSU, kDragTextPropSourceLink, kDragTextValue) ) { ODBoolean validLink = kODTrue; TRY StorageUnitGetValue(_fTestDragSU, ev, sizeof(ODStorageUnitRef),&aSURef); if ( _fTestDragSU->IsValidStorageUnitRef(ev, aSURef) ) { _fSrcLink.linkSource = _fDraft->AcquireLinkSource(ev, _fTestDragSU->GetIDFromStorageUnitRef(ev, aSURef)); StorageUnitGetValue(_fTestDragSU, ev, sizeof(ODSShort), (ODValue) &_fSrcLink.start); StorageUnitGetValue(_fTestDragSU, ev, sizeof(ODSShort), (ODValue) &_fSrcLink.end); StorageUnitGetValue(_fTestDragSU, ev, sizeof(ODULong), (ODValue) &_fSrcLink.change); // Ensure the link source references this part _fSrcLink.linkSource->SetSourcePart(ev, somSelf->GetStorageUnit(ev)); } else { validLink = kODFalse; } CATCH_ALL validLink = kODFalse; ENDTRY if ( !validLink ) { _fTestDragSU->SetOffset(ev, 0); _fTestDragSU->DeleteValue(ev, _fTestDragSU->GetSize(ev)); _fSrcLink.linkSource = (ODLinkSource*) kODNULL; _fSrcLink.start = -1; _fSrcLink.end = -1; _fSrcLink.change = kODUnknownUpdate; } } if ( SUExistsThenFocus(ev, _fTestDragSU, kDragTextPropDestLink, kDragTextValue) ) { ODBoolean validLink = kODTrue; TRY StorageUnitGetValue(_fTestDragSU, ev, sizeof(ODStorageUnitRef),&aSURef); if ( _fTestDragSU->IsValidStorageUnitRef(ev, aSURef) ) { _fDstLink.link = _fDraft->AcquireLink(ev, _fTestDragSU->GetIDFromStorageUnitRef(ev, aSURef), (ODLinkSpec*) kODNULL); StorageUnitGetValue(_fTestDragSU, ev, sizeof(ODSShort), (ODValue) &_fDstLink.start); StorageUnitGetValue(_fTestDragSU, ev, sizeof(ODSShort), (ODValue) &_fDstLink.end); StorageUnitGetValue(_fTestDragSU, ev, sizeof(ODLinkInfo), (ODValue) &_fDstLink.info); ODType kind = (ODType) ODNewPtr((ODULong) _fDstLink.info.kind, kDefaultHeapID); StorageUnitGetValue(_fTestDragSU, ev, (ODULong) _fDstLink.info.kind, (ODValue) kind); _fDstLink.info.kind = kind; } else { validLink = kODFalse; } CATCH_ALL validLink = kODFalse; ENDTRY if ( !validLink ) { _fTestDragSU->SetOffset(ev, 0); _fTestDragSU->DeleteValue(ev, _fTestDragSU->GetSize(ev)); _fDstLink.link = (ODLink*) kODNULL; _fDstLink.start = -1; _fDstLink.end = -1; } } } else #endif if ( SUExistsThenFocus(ev, partSU, kODPropContents, kODApplestxt) ) { Handle textHandle; StScrpHandle stylHandle; ReadStyledText(ev, partSU, &textHandle, &stylHandle); _fTextHandle = textHandle; _fStylHandle = stylHandle; } else if ( partSU->Exists(ev, kODPropContents, kODAppleTEXT, 0) ) { // read in TEXT partSU->Focus(ev, kODPropContents, kODPosUndefined, kODAppleTEXT, 0, kODPosUndefined); textSize = partSU->GetSize(ev); if (textSize > 0) { _fTextHandle = (Handle) ODNewHandle(textSize); ODLockHandle((ODHandle) _fTextHandle); StorageUnitGetValue(partSU, ev, textSize, (ODValue)*_fTextHandle); ODUnlockHandle((ODHandle) _fTextHandle); } // read in styl if ( SUExistsThenFocus(ev, partSU, kODPropContents, kODApplestyl) ) { stylSize = partSU->GetSize(ev); if (stylSize > 0) { _fStylHandle = (StScrpHandle)ODNewHandle(stylSize); ODLockHandle((ODHandle) _fStylHandle); StorageUnitGetValue(partSU, ev, stylSize, (ODValue)*_fStylHandle); ODUnlockHandle((ODHandle) _fStylHandle); } } } else if ( partSU->Exists(ev, kODPropContents, kODAppleFileTEXT, 0) ) { PRINT("DragText: Initializing from TEXT file\n"); FSSpec fileSpec; if ( GetFSSpecFromHFSProperty(ev, partSU, &fileSpec) ) { ODBoolean truncated; PRINT("DragText: Reading TEXT file\n"); TRY _fTextHandle = ReadTextFile(&fileSpec, &truncated); CATCH_ALL // Put up an alert; unfortunately this part has no frame yet RERAISE; ENDTRY; if ( &truncated ) { // Put up an alert; unfortunately this part has no frame yet } // SURemoveValue(ev, partSU, kODPropContents, kODAppleFileTEXT); // $$$$$ Right thing to do? // SURemoveValue(ev, partSU, kODPropContents, kODApplehfs); SUForceFocus(ev, partSU, kODPropContents, kODAppleTEXT); } else THROW(kDragTextErrCantReadTEXTFile); } else { // No content type that this editor handles was found. // This editor should not have been bound to the part. // Throw an error. THROW(kDragTextErrNoSupportedContent); } SOM_CATCH_ALL SOM_ENDTRY }